Geo update WIP
This commit is contained in:
5
classes/errors/geo.py
Normal file
5
classes/errors/geo.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class PlaceNotFoundError(Exception):
|
||||
"""Query provided did not lead to any city or populated area"""
|
||||
def __init__(self, query):
|
||||
self.query = query
|
||||
super().__init__(f"Could not find any place on geonames.org of feature classes A and P by query '{self.query}'")
|
@@ -8,9 +8,10 @@ from typing import Any, List, Literal, Union
|
||||
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat, Message, Photo, Video, Document, Animation, Voice, ForceReply, ReplyKeyboardMarkup
|
||||
from pyrogram.errors import bad_request_400
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from classes.errors.geo import PlaceNotFoundError
|
||||
from modules.database import col_tmp, col_users, col_context, col_warnings, col_applications, col_sponsorships, col_messages
|
||||
from modules.logging import logWrite
|
||||
from modules.utils import configGet, locale, should_quote
|
||||
from modules.utils import configGet, find_location, locale, should_quote
|
||||
|
||||
class DefaultApplicationTemp(dict):
|
||||
def __init__(self, user: int, reapply: bool = False):
|
||||
@@ -350,6 +351,10 @@ class HoloUser():
|
||||
)
|
||||
|
||||
progress = col_tmp.find_one({"user": self.id, "type": "application"})
|
||||
|
||||
if progress is None:
|
||||
return
|
||||
|
||||
stage = progress["stage"]
|
||||
|
||||
if self.sponsorship_state()[0] == "fill":
|
||||
@@ -385,13 +390,16 @@ class HoloUser():
|
||||
|
||||
elif stage == 3:
|
||||
try:
|
||||
result = (get(f"http://api.geonames.org/searchJSON?q={query}&maxRows=1&countryBias=UA&lang=uk&orderby=relevance&featureClass=P&featureClass=A&username={configGet('username', 'geocoding')}")).json()
|
||||
progress["application"][str(stage)] = result["geonames"][0]
|
||||
progress["application"][str(stage)] = find_location(query)
|
||||
if ("lat" in progress["application"][str(stage)] and "lng" in progress["application"][str(stage)]):
|
||||
progress["application"][str(stage)]["loc"] = [progress["application"][str(stage)]["lng"], progress["application"][str(stage)]["lat"]]
|
||||
del progress["application"][str(stage)]["lat"]
|
||||
del progress["application"][str(stage)]["lng"]
|
||||
col_tmp.update_one({"user": {"$eq": self.id}, "type": {"$eq": "application"}}, {"$set": {"application": progress["application"], "stage": progress["stage"]+1}})
|
||||
await msg.reply_text(locale(f"question3_found", "message", locale=self.locale).format(result["geonames"][0]["name"], result["geonames"][0]["adminName1"]))
|
||||
await msg.reply_text(locale("question3_found", "message", locale=self.locale).format(progress["application"][str(stage)]["name"], progress["application"][str(stage)]["adminName1"]))
|
||||
await msg.reply_text(locale(f"question{stage+1}", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage+1}", "force_reply", locale=self.locale))))
|
||||
except (ValueError, KeyError, IndexError):
|
||||
await msg.reply_text(locale(f"question3_invalid", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
except PlaceNotFoundError:
|
||||
await msg.reply_text(locale("question3_invalid", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
return
|
||||
except Exception as exp:
|
||||
await msg.reply_text(locale("question3_error", "message", locale=self.locale), reply_markup=ForceReply(placeholder=str(locale(f"question{stage}", "force_reply", locale=self.locale))))
|
||||
@@ -470,6 +478,10 @@ class HoloUser():
|
||||
if col_tmp.find_one({"user": self.id, "type": "sponsorship"}) is not None:
|
||||
|
||||
progress = col_tmp.find_one({"user": self.id, "type": "sponsorship"})
|
||||
|
||||
if progress is None:
|
||||
return
|
||||
|
||||
stage = progress["stage"]
|
||||
|
||||
if progress["state"] == "fill" and progress["sent"] is False:
|
||||
|
Reference in New Issue
Block a user