This repository was archived by the owner on Jan 18, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
This repository was archived by the owner on Jan 18, 2021. It is now read-only.
Proposal: Save expiration time of a quest in the db so only non expired quests are being used #43
Copy link
Copy link
Open
Description
You have the coordinates of a pokestop, based on those coordinates you can get the timezone and determine the local midnight time of the pokestop and know the expiration time of the quest because of it.
This way you can have a clean map, clean set of pokestops after midnight,...
In RocketMapPlusPlus the following logic was used:
utcnow_datetime = datetime.utcnow()
quest_json = fort_search_response_json["challengeQuest"]["quest"]
quest_pokestop = pokestops.get(quest_json["fortId"], Pokestop.get_stop(quest_json["fortId"]))
pokestop_timezone_offset = get_timezone_offset(quest_pokestop['latitude'], quest_pokestop['longitude'])
pokestop_localtime = utcnow_datetime + timedelta(minutes=pokestop_timezone_offset)
next_day_localtime = datetime(
year=pokestop_localtime.year,
month=pokestop_localtime.month,
day=pokestop_localtime.day
) + timedelta(days=1)
next_day_utc = next_day_localtime - timedelta(minutes=pokestop_timezone_offset)
for the timezoneoffset, the following code was used:
def get_timezone_offset(lat, lng):
args = get_args()
(timezone_offset, status) = get_timezonefinder_timezone_offset(lat, lng)
if status != "OK":
(timezone_offset, status) = get_gmaps_timezone_offset(lat, lng, args.gmaps_key)
if status != "OK":
timezone_offset = args.quest_timezone_offset
return timezone_offset
def get_timezonefinder_timezone_offset(lat, lng):
from pytz import timezone
import pytz
utc = pytz.utc
try:
today = datetime.now()
tz = tf.certain_timezone_at(lat=lat, lng=lng)
if tz is None:
tz = tf.timezone_at(lat=lat, lng=lng)
if tz is None:
tz = tf.closest_timezone_at(lat=lat, lng=lng)
if tz is None:
return (0, "UNKNOWNN_TIMEZONE")
tz_target = timezone(tz)
today_target = tz_target.localize(today)
today_utc = utc.localize(today)
status = "OK"
timezone_offset = int((today_utc - today_target).total_seconds() / 60)
except Exception as e:
log.exception('Unable to retrieve timezone from timezonefinder: %s.', e)
status = 'UNKNOWN_ERROR'
timezone_offset = None
return (timezone_offset, status)
def get_gmaps_timezone_offset(lat, lng, gmaps_key):
try:
r_session = requests.Session()
response = r_session.get((
'https://maps.googleapis.com/maps/api/timezone/json?' +
'location={},{}×tamp={}&key={}').format(lat, lng, time.time(), gmaps_key),
timeout=5)
response = response.json()
status = response['status']
timezone_offset = (response.get('rawOffset', 0) + response.get('dstOffset', 0)) / 60
except Exception as e:
log.exception('Unable to retrieve timezone from Google APIs: %s.', e)
status = 'UNKNOWN_ERROR'
timezone_offset = None
return (timezone_offset, status)
Metadata
Metadata
Assignees
Labels
No labels