amélioration de la définition des images
This commit is contained in:
30
spoutnik.py
30
spoutnik.py
@@ -10,6 +10,7 @@ from shapely.geometry import Point
|
||||
from geopy.distance import geodesic
|
||||
from geopy.geocoders import Nominatim
|
||||
from math import sinh, atan, pi, log, tan, cos, ceil
|
||||
from PIL import Image
|
||||
|
||||
geolocator = Nominatim(user_agent="discord-bot-spoutnik")
|
||||
|
||||
@@ -56,16 +57,27 @@ class Game:
|
||||
return
|
||||
|
||||
output = ""
|
||||
if self.target and not self.winner:
|
||||
output = f":expressionless: Le lieu précédent était [ici](<https://www.google.ch/maps/@{self.target[0]},{self.target[1]},{self.preset["zoom"]+1}z>).\n\n"
|
||||
self.preset = preset
|
||||
zoom = self.preset["zoom"]
|
||||
if self.target and not self.winner:
|
||||
output = f":expressionless: Le lieu précédent était [ici](<https://www.google.ch/maps/@{self.target[0]},{self.target[1]},{zoom}z>).\n\n"
|
||||
random_lat, random_lon = random_point(self.preset["geojson_file"])
|
||||
tile_x, tile_y = wgs84_to_tile(random_lat, random_lon, zoom)
|
||||
req = requests.get(f"https://khms2.google.com/kh/v=1000?x={tile_x}&y={tile_y}&z={zoom}")
|
||||
with open(self.file, "wb") as f:
|
||||
f.write(req.content)
|
||||
self.target = tile_to_wgs84(tile_x + 0.5, tile_y + 0.5, zoom)
|
||||
tile_x, tile_y = wgs84_to_tile(random_lat, random_lon, zoom+1)
|
||||
with open("/tmp/a.jpg", "wb") as f:
|
||||
f.write(requests.get(f"https://khms2.google.com/kh/v=1000?x={tile_x}&y={tile_y}&z={zoom+1}").content)
|
||||
with open("/tmp/b.jpg", "wb") as f:
|
||||
f.write(requests.get(f"https://khms2.google.com/kh/v=1000?x={tile_x+1}&y={tile_y}&z={zoom+1}").content)
|
||||
with open("/tmp/c.jpg", "wb") as f:
|
||||
f.write(requests.get(f"https://khms2.google.com/kh/v=1000?x={tile_x}&y={tile_y+1}&z={zoom+1}").content)
|
||||
with open("/tmp/d.jpg", "wb") as f:
|
||||
f.write(requests.get(f"https://khms2.google.com/kh/v=1000?x={tile_x+1}&y={tile_y+1}&z={zoom+1}").content)
|
||||
abcd = Image.new("RGB", (256 * 2, 256 * 2))
|
||||
abcd.paste(Image.open("/tmp/a.jpg"), (0, 0))
|
||||
abcd.paste(Image.open("/tmp/b.jpg"), (256, 0))
|
||||
abcd.paste(Image.open("/tmp/c.jpg"), (0, 256))
|
||||
abcd.paste(Image.open("/tmp/d.jpg"), (256, 256))
|
||||
abcd.save(self.file)
|
||||
self.target = tile_to_wgs84(tile_x + 1, tile_y + 1, zoom+1)
|
||||
self.winner = None
|
||||
self.last_player = None
|
||||
self.last_datetime = None
|
||||
@@ -125,13 +137,13 @@ class Game:
|
||||
self.winner = message.author
|
||||
self.resetters = set()
|
||||
output = f":trophy: YOUPI ! {message.author.mention} a trouvé le lieu ! :trophy:"
|
||||
output += f"\n\n[Lieu exact](<https://www.google.ch/maps/@{self.target[0]},{self.target[1]},{zoom}z>)"
|
||||
output += f"\n\n[Lieu exact](<https://www.google.ch/maps/@{self.target[0]},{self.target[1]},{zoom+1}z>)"
|
||||
await self.channel.send(output)
|
||||
else:
|
||||
try:
|
||||
address = clean_address(geolocator.reverse((lat, lon), language="fr").address)
|
||||
except ValueError:
|
||||
address = "un lieu apparemment invalide"
|
||||
output = f"{message.author.mention} propose [un point](<https://www.google.ch/maps/@{lat},{lon},{zoom}z>) proche de {address}."
|
||||
output = f"{message.author.mention} propose [un point](<https://www.google.ch/maps/@{lat},{lon},{zoom+1}z>) proche de {address}."
|
||||
output += f"\n\nC'est pas ça chef, mais tu es à moins de {blurred_distance} de [la cible](<{self.jump_url}>) !"
|
||||
await self.channel.send(output)
|
||||
Reference in New Issue
Block a user