...
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import os
|
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from nextcord import Embed, Color
|
from nextcord import Embed, Color
|
||||||
@@ -9,6 +8,7 @@ from bs4 import BeautifulSoup as bs
|
|||||||
from .settings import *
|
from .settings import *
|
||||||
from .saints import SAINTS
|
from .saints import SAINTS
|
||||||
|
|
||||||
|
|
||||||
def citation():
|
def citation():
|
||||||
try:
|
try:
|
||||||
req = requests.get("http://www.unjourunpoeme.fr")
|
req = requests.get("http://www.unjourunpoeme.fr")
|
||||||
@@ -22,27 +22,29 @@ def citation():
|
|||||||
except Exception:
|
except Exception:
|
||||||
return "Impossible de trouver la citation du jour. Bouuuh !"
|
return "Impossible de trouver la citation du jour. Bouuuh !"
|
||||||
|
|
||||||
|
|
||||||
def saint():
|
def saint():
|
||||||
today = datetime.now().strftime("%m/%d")
|
today = datetime.now().strftime("%m/%d")
|
||||||
saint = SAINTS[today]
|
return SAINTS[today]
|
||||||
return saint
|
|
||||||
|
|
||||||
def weather_emoji(_id):
|
def weather_emoji(_id):
|
||||||
emojis = {re.compile(r"2.."):":thunder_cloud_rain:",
|
emojis = {re.compile(r"2.."): ":thunder_cloud_rain:",
|
||||||
re.compile(r"3.."):":white_sun_rain_cloud:",
|
re.compile(r"3.."): ":white_sun_rain_cloud:",
|
||||||
re.compile(r"5.."):":cloud_rain:",
|
re.compile(r"5.."): ":cloud_rain:",
|
||||||
re.compile(r"6.."):":snowflake:",
|
re.compile(r"6.."): ":snowflake:",
|
||||||
re.compile(r"7.."):":interrobang:",
|
re.compile(r"7.."): ":interrobang:",
|
||||||
re.compile(r"800"):":sunny:",
|
re.compile(r"800"): ":sunny:",
|
||||||
re.compile(r"801"):":white_sun_small_cloud:",
|
re.compile(r"801"): ":white_sun_small_cloud:",
|
||||||
re.compile(r"80[23]"):":white_sun_cloud:",
|
re.compile(r"80[23]"): ":white_sun_cloud:",
|
||||||
re.compile(r"804"):":cloud:"}
|
re.compile(r"804"): ":cloud:"}
|
||||||
try:
|
try:
|
||||||
code = next(emoji[1] for emoji in emojis.items() if emoji[0].match(str(_id)))
|
code = next(emoji[1] for emoji in emojis.items() if emoji[0].match(str(_id)))
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
code = ":negative_squared_cross_mark:"
|
code = ":negative_squared_cross_mark:"
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
def weather(lat, lon):
|
def weather(lat, lon):
|
||||||
r = requests.get(f"https://api.openweathermap.org/data/2.5/"
|
r = requests.get(f"https://api.openweathermap.org/data/2.5/"
|
||||||
f"onecall?lat={lat}&lon={lon}&appid={OWM_KEY}&lang=fr&units=metric")
|
f"onecall?lat={lat}&lon={lon}&appid={OWM_KEY}&lang=fr&units=metric")
|
||||||
@@ -51,45 +53,48 @@ def weather(lat, lon):
|
|||||||
next_hours = []
|
next_hours = []
|
||||||
for i in (2, 8, 14):
|
for i in (2, 8, 14):
|
||||||
hourly = j["hourly"][i]
|
hourly = j["hourly"][i]
|
||||||
time = datetime.fromtimestamp(hourly["dt"]).strftime("%H:%M")
|
next_hours.append({"time": datetime.fromtimestamp(hourly["dt"]).strftime("%H:%M"),
|
||||||
temp = round(hourly["temp"])
|
"emoji": weather_emoji(hourly["weather"][0]["id"]),
|
||||||
feels_like = hourly["feels_like"]
|
"description": hourly["weather"][0]["description"],
|
||||||
humidity = hourly["humidity"]
|
"temp": round(hourly["temp"]),
|
||||||
wind_speed = round(hourly["wind_speed"] * 3.6)
|
"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
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return next_hours
|
return next_hours
|
||||||
|
|
||||||
|
|
||||||
def digest():
|
def digest():
|
||||||
try:
|
try:
|
||||||
locale.setlocale(locale.LC_ALL, "fr_CH.utf-8")
|
locale.setlocale(locale.LC_ALL, "fr_CH.utf-8")
|
||||||
except locale.Error:
|
except locale.Error:
|
||||||
pass
|
pass
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
d = now.strftime("%A %-d %B")
|
|
||||||
c = citation()
|
include_citation = False
|
||||||
s = saint()
|
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 {now.strftime('%A %-d %B')} ({saint()})"
|
||||||
|
|
||||||
|
if include_citation:
|
||||||
|
embed.description += f"\n\n{citation()}\n\u200B"
|
||||||
|
|
||||||
|
if include_weather:
|
||||||
w_strings = []
|
w_strings = []
|
||||||
for w in weather(46.5196661, 6.6325467):
|
for w in weather(46.5196661, 6.6325467):
|
||||||
w_strings.append(f"{w['emoji']} {w['description']} ({w['temp']}°C, {w['wind_speed']} km/h)")
|
w_strings.append(f"{w['emoji']} {w['description']} ({w['temp']}°C, {w['wind_speed']} km/h)")
|
||||||
|
|
||||||
embed = Embed()
|
|
||||||
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="Matin", value=w_strings[0])
|
||||||
embed.add_field(name="Après-midi", value=w_strings[1])
|
embed.add_field(name="Après-midi", value=w_strings[1])
|
||||||
embed.add_field(name="Soir", value=w_strings[2])
|
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
|
return embed
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(citation())
|
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