...
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
import requests
|
||||
from datetime import datetime
|
||||
from nextcord import Embed, Color
|
||||
@@ -9,6 +8,7 @@ from bs4 import BeautifulSoup as bs
|
||||
from .settings import *
|
||||
from .saints import SAINTS
|
||||
|
||||
|
||||
def citation():
|
||||
try:
|
||||
req = requests.get("http://www.unjourunpoeme.fr")
|
||||
@@ -22,27 +22,29 @@ def citation():
|
||||
except Exception:
|
||||
return "Impossible de trouver la citation du jour. Bouuuh !"
|
||||
|
||||
|
||||
def saint():
|
||||
today = datetime.now().strftime("%m/%d")
|
||||
saint = SAINTS[today]
|
||||
return saint
|
||||
return SAINTS[today]
|
||||
|
||||
|
||||
def weather_emoji(_id):
|
||||
emojis = {re.compile(r"2.."):":thunder_cloud_rain:",
|
||||
re.compile(r"3.."):":white_sun_rain_cloud:",
|
||||
re.compile(r"5.."):":cloud_rain:",
|
||||
re.compile(r"6.."):":snowflake:",
|
||||
re.compile(r"7.."):":interrobang:",
|
||||
re.compile(r"800"):":sunny:",
|
||||
re.compile(r"801"):":white_sun_small_cloud:",
|
||||
re.compile(r"80[23]"):":white_sun_cloud:",
|
||||
re.compile(r"804"):":cloud:"}
|
||||
emojis = {re.compile(r"2.."): ":thunder_cloud_rain:",
|
||||
re.compile(r"3.."): ":white_sun_rain_cloud:",
|
||||
re.compile(r"5.."): ":cloud_rain:",
|
||||
re.compile(r"6.."): ":snowflake:",
|
||||
re.compile(r"7.."): ":interrobang:",
|
||||
re.compile(r"800"): ":sunny:",
|
||||
re.compile(r"801"): ":white_sun_small_cloud:",
|
||||
re.compile(r"80[23]"): ":white_sun_cloud:",
|
||||
re.compile(r"804"): ":cloud:"}
|
||||
try:
|
||||
code = next(emoji[1] for emoji in emojis.items() if emoji[0].match(str(_id)))
|
||||
except StopIteration:
|
||||
code = ":negative_squared_cross_mark:"
|
||||
return code
|
||||
|
||||
|
||||
def weather(lat, lon):
|
||||
r = requests.get(f"https://api.openweathermap.org/data/2.5/"
|
||||
f"onecall?lat={lat}&lon={lon}&appid={OWM_KEY}&lang=fr&units=metric")
|
||||
@@ -51,45 +53,48 @@ def weather(lat, lon):
|
||||
next_hours = []
|
||||
for i in (2, 8, 14):
|
||||
hourly = j["hourly"][i]
|
||||
time = datetime.fromtimestamp(hourly["dt"]).strftime("%H:%M")
|
||||
temp = round(hourly["temp"])
|
||||
feels_like = hourly["feels_like"]
|
||||
humidity = hourly["humidity"]
|
||||
wind_speed = round(hourly["wind_speed"] * 3.6)
|
||||
description = hourly["weather"][0]["description"]
|
||||
emoji = weather_emoji(hourly["weather"][0]["id"])
|
||||
next_hours.append({"time":time,
|
||||
"emoji":emoji,
|
||||
"description":description,
|
||||
"temp":temp,
|
||||
"wind_speed":wind_speed
|
||||
next_hours.append({"time": datetime.fromtimestamp(hourly["dt"]).strftime("%H:%M"),
|
||||
"emoji": weather_emoji(hourly["weather"][0]["id"]),
|
||||
"description": hourly["weather"][0]["description"],
|
||||
"temp": round(hourly["temp"]),
|
||||
"wind_speed": round(hourly["wind_speed"] * 3.6)
|
||||
})
|
||||
|
||||
return next_hours
|
||||
|
||||
|
||||
def digest():
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, "fr_CH.utf-8")
|
||||
except locale.Error:
|
||||
pass
|
||||
now = datetime.now()
|
||||
d = now.strftime("%A %-d %B")
|
||||
c = citation()
|
||||
s = saint()
|
||||
w_strings = []
|
||||
for w in weather(46.5196661, 6.6325467):
|
||||
w_strings.append(f"{w['emoji']} {w['description']} ({w['temp']}°C, {w['wind_speed']} km/h)")
|
||||
|
||||
embed = Embed()
|
||||
include_citation = False
|
||||
include_weather = True
|
||||
include_artwork = True
|
||||
|
||||
embed = Embed(color=[Color.red(), Color.gold(), Color.orange(), Color.blue(), Color.green(), Color.magenta(), Color.purple()][now.weekday()])
|
||||
embed.title = "Bonjour !"
|
||||
embed.description = f"Nous sommes le {d} ({s})\n\n{c}\n\u200B"
|
||||
colors = [Color.red(), Color.gold(), Color.orange(), Color.blue(), Color.green(), Color.magenta(), Color.purple()]
|
||||
embed.color = colors[now.weekday()]
|
||||
embed.add_field(name="Matin", value=w_strings[0])
|
||||
embed.add_field(name="Après-midi", value=w_strings[1])
|
||||
embed.add_field(name="Soir", value=w_strings[2])
|
||||
embed.description = f"Nous sommes le {now.strftime('%A %-d %B')} ({saint()})"
|
||||
|
||||
if include_citation:
|
||||
embed.description += f"\n\n{citation()}\n\u200B"
|
||||
|
||||
if include_weather:
|
||||
w_strings = []
|
||||
for w in weather(46.5196661, 6.6325467):
|
||||
w_strings.append(f"{w['emoji']} {w['description']} ({w['temp']}°C, {w['wind_speed']} km/h)")
|
||||
embed.add_field(name="Matin", value=w_strings[0])
|
||||
embed.add_field(name="Après-midi", value=w_strings[1])
|
||||
embed.add_field(name="Soir", value=w_strings[2])
|
||||
|
||||
if include_artwork:
|
||||
embed.set_image("https://uploads3.wikiart.org/00340/images/tintoretto/the-miracle-of-st-mark-freeing-the-slave.jpg")
|
||||
embed.set_footer(text="Coucou")
|
||||
|
||||
return embed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(citation())
|
||||
|
||||
8
foo.py
Normal file
8
foo.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import requests
|
||||
import json
|
||||
from bs4 import BeautifulSoup as bs
|
||||
|
||||
html = requests.get("https://www.wikiart.org/").text
|
||||
soup = bs(html, features="html.parser")
|
||||
|
||||
print(json.loads(soup.find("main", {"class": "wiki-layout-main-page"})["ng-init"].splitlines()[0][28:-1]))
|
||||
Reference in New Issue
Block a user