Open roshii-11 opened 1 year ago
Same here
Pareil ici
merci j'ai réussi a régler le problème , dans le fichier > investpy\utils\constant.py J'ai modifier le dictionnaire TIMEZONES par ces bonnes valeurs > https://github.com/alvarobartt/investpy/issues/331#issuecomment-952944746
If your having trouble with time zones and inconsistent times, you will need to scrape the time zone values off of Investing.com/economic-calendar. I've wrote a script to do exactly that, simply 'pip install BeautifulSoup4' and Run.
`import requests from bs4 import BeautifulSoup import re
def scrape_timezones(): url = "https://www.investing.com/economic-calendar/"
headers = {
'User-Agent': (
'Mozilla/5.0 (Windows NT 10.0; Win64 x64) '
'AppleWebKit/537.36 (KHTML, Like Gecko) '
'Chrome/58.0.3029.110 Safari/537.3'
)
}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
except requests.exceptions.RequestException as e:
print(f"Error fetching the page: {e}")
return
soup = BeautifulSoup(response.content, 'html.parser')
timezone_div = soup.find('div', id='economicCurrentTimePop')
if not timezone_div:
print("Timezone div with id 'economicCurrentTimePop' not found")
return
ul = timezone_div.find('ul', class_='js-scrollable-block')
if not ul:
print("Unordered list with class 'js-scrollable-block' not found")
return
TIMEZONES = {}
for li in ul.find_all('li', class_='addRow'):
id_attr = li.get('id', '')
# Extract the number after 'liTz' using regex
match_id = re.match(r'liTz(\d+)', id_attr)
if not match_id:
continue # Skip if the id does not match the pattern
tz_number = int(match_id.group(1))
# Extract the text content of the list item
text = li.get_text(strip=True)
# Extract the GMT offset using regex
match_tz = re.match(r'\(GMT\s*([+-]?\d{1,2}:\d{2})?\)', text)
if match_tz:
offset = match_tz.group(1)
if offset:
timezone = f"GMT {offset}"
else:
timezone = "GMT"
else:
# Handle cases where the format might be different
print(f"Unrecognized timezone format: '{text}'")
continue
# Append the tz_number to the corresponding timezone in the dictionary
if timezone not in TIMEZONES:
TIMEZONES[timezone] = []
TIMEZONES[timezone].append(tz_number)
# Sort the dictionary by GMT offset for better readability
sorted_TIMEZONES = dict(sorted(
TIMEZONES.items(),
key=lambda item: parse_gmt_offset(item[0])
))
# Print the TIMEZONES dictionary in the desired format
print("TIMEZONES = {")
for tz, numbers in sorted_TIMEZONES.items():
numbers_sorted = sorted(numbers)
numbers_str = ', '.join(map(str, numbers_sorted))
print(f" '{tz}': [{numbers_str}],")
print("}")
def parse_gmt_offset(tz_str): """ Helper function to convert GMT offset string to a sortable value. For example: 'GMT -11:00' -> -11.0 'GMT +5:30' -> 5.5 'GMT' -> 0 """ if tz_str == "GMT": return 0 match = re.match(r'GMT\s([+-]?)(\d{1,2}):(\d{2})', tz_str) if not match: return 0 # Default to 0 if unrecognized sign = -1 if match.group(1) == '-' else 1 hours = int(match.group(2)) minutes = int(match.group(3)) return sign (hours + minutes / 60)
if name == "main": scrape_timezones()`
il y a un problème dans le time_zone de investpy pour les annonces économiques :
A la première exécution du code tous va bien , puis dans les autres ça affiche gmt +1 alors que je n'ai rien modifier !
Comment régler ce problème svp
exemple de ce que j'ai dans le CMD :
Et puis d'un coup sans raison et sans modification du code dans la même minute :