【发布时间】:2021-10-02 17:20:37
【问题描述】:
我对 Python 还是很陌生,正在尝试编写一个可以根据经度计算位置实时时间的代码。
它已经工作了,但是现在,它需要参数self 填充。我定义了self,现在解决了,但现在如果我尝试使用offset(City, self=tf),它会给我这个错误:
Traceback (most recent call last):
File "C:\Users\Marvi\PycharmProjects\pythonProject1\main.py", line 55, in <module>
GMTcor = time_in - offset(City, self=tf) * 60 + realTime
File "C:\Users\Marvi\PycharmProjects\pythonProject1\main.py", line 45, in offset
tz_target = timezone(tf.certain_timezone_at(self,lat=target['lat'], lng=target['lng']))
File "C:\Users\Marvi\anaconda3\envs\pythonProject1\lib\site-packages\timezonefinder\timezonefinder.py", line 744, in certain_timezone_at
timezone = self._get_unique_zone(shortcut_id_x, shortcut_id_y)
TypeError: _get_unique_zone() missing 1 required positional argument: 'shortcut_id_y'
我不知道如何解决它...请帮助我! 整个代码都在这里:(我知道它很乱)
from geopy.geocoders import Nominatim
from datetime import timedelta
from pytz import timezone
import pytz
import datetime
from timezonefinder import TimezoneFinder
address = input("Insert place: ")
geolocator = Nominatim(user_agent="Time Correction Calculator")
location = geolocator.geocode(address)
print(location.address)
t = input("Insert time (hh:mm): ")
(h, m) = t.split(':')
time_in = int(h) * 60 + int(m)
date_input = input("Insert date (dd.mm.yyyy): ")
utc = pytz.utc
tf = TimezoneFinder
def offset(target, self):
today = datetime.datetime.strptime(date_input, '%d.%m.%Y') # reading of date_in and Splitting it
tz_target = timezone(tf.certain_timezone_at(self,lat=target['lat'],
lng = target['lng'])) # Searching timezone by coordinates
today_target = tz_target.localize(today)
today_utc = utc.localize(today)
return (today_utc - today_target).total_seconds() / 3600 # Calculating the timezone in hours
City = dict({'lat' : location.latitude, 'lng' : location.longitude})
realTime : float = location.longitude * 4 # Longitude to minutes
realTime = round(realTime)
Correction = time_in - offset(City, self=tf) * 60 + realTime # Calculating the real time in minutes
print(str(timedelta(hours = GMTcor / 60))[:-3]) # printing the real Time
【问题讨论】: