py2ls 0.2.4.23__py3-none-any.whl → 0.2.4.25__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- py2ls/.DS_Store +0 -0
- py2ls/.git/.DS_Store +0 -0
- py2ls/.git/index +0 -0
- py2ls/.git/objects/.DS_Store +0 -0
- py2ls/.git/refs/.DS_Store +0 -0
- py2ls/data/.DS_Store +0 -0
- py2ls/data/styles/.DS_Store +0 -0
- py2ls/ec2ls.py +61 -0
- py2ls/ips.py +297 -229
- py2ls/ml2ls.py +996 -155
- py2ls/nl2ls.py +283 -0
- py2ls/plot.py +351 -40
- {py2ls-0.2.4.23.dist-info → py2ls-0.2.4.25.dist-info}/METADATA +1 -1
- {py2ls-0.2.4.23.dist-info → py2ls-0.2.4.25.dist-info}/RECORD +15 -11
- py2ls/ml2ls copy.py +0 -2906
- {py2ls-0.2.4.23.dist-info → py2ls-0.2.4.25.dist-info}/WHEEL +0 -0
py2ls/.DS_Store
CHANGED
Binary file
|
py2ls/.git/.DS_Store
ADDED
Binary file
|
py2ls/.git/index
CHANGED
Binary file
|
Binary file
|
Binary file
|
py2ls/data/.DS_Store
CHANGED
Binary file
|
py2ls/data/styles/.DS_Store
CHANGED
Binary file
|
py2ls/ec2ls.py
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
def get_trend(
|
2
|
+
keywords: list = None, # ["AI", "Python", "Data Science"]
|
3
|
+
timezone: str = "Europe/Berlin", # minutes differ from UTC
|
4
|
+
cat=0,
|
5
|
+
timeframe="today 12-m",
|
6
|
+
geo="DE",
|
7
|
+
gprop="",
|
8
|
+
**kwargs
|
9
|
+
):
|
10
|
+
from pytrends.request import TrendReq
|
11
|
+
from pytrends.exceptions import TooManyRequestsError
|
12
|
+
import pytz
|
13
|
+
from datetime import datetime
|
14
|
+
import time
|
15
|
+
import requests
|
16
|
+
from urllib3.util.retry import Retry
|
17
|
+
|
18
|
+
if isinstance(timezone, str):
|
19
|
+
stadt = pytz.timezone(timezone)
|
20
|
+
current_time = datetime.now(stadt) # This will be timezone-aware
|
21
|
+
# Convert the timezone-aware datetime to naive UTC datetime
|
22
|
+
naive_time = current_time.astimezone(pytz.utc).replace(tzinfo=None)
|
23
|
+
tz_offset = stadt.utcoffset(naive_time).seconds // 60 # in minutes
|
24
|
+
elif isinstance(timezone, int):
|
25
|
+
tz_offset = timezone
|
26
|
+
|
27
|
+
# Initialize TrendReq with correct timezone offset
|
28
|
+
pytrends = TrendReq(hl="en-US", tz=tz_offset )
|
29
|
+
|
30
|
+
# Ensure that keywords are in list form
|
31
|
+
if isinstance(keywords, str):
|
32
|
+
keywords = [keywords]
|
33
|
+
|
34
|
+
pytrends.build_payload(keywords, cat=cat, timeframe=timeframe, geo=geo, gprop=gprop)
|
35
|
+
|
36
|
+
res = {}
|
37
|
+
# Try fetching data with error handling
|
38
|
+
for func_name, fetch_func in [
|
39
|
+
("interest_over_time", pytrends.interest_over_time),
|
40
|
+
("related_topics", pytrends.related_topics),
|
41
|
+
("related_queries", pytrends.related_queries),
|
42
|
+
("categories", pytrends.categories)
|
43
|
+
]:
|
44
|
+
try:
|
45
|
+
print(f"Fetching {func_name}...")
|
46
|
+
res[func_name] = fetch_func()
|
47
|
+
print(f"done: {func_name}")
|
48
|
+
except TooManyRequestsError:
|
49
|
+
print(f"Too many requests error for {func_name}. Retrying...")
|
50
|
+
time.sleep(5) # Delay to avoid spamming the server
|
51
|
+
if retries > 0:
|
52
|
+
return get_trend(keywords, timezone, cat, timeframe, geo, gprop, retries=retries-1)
|
53
|
+
res[func_name] = None
|
54
|
+
except requests.exceptions.RequestException as e:
|
55
|
+
print(f"Request error for {func_name}: {e}")
|
56
|
+
res[func_name] = None
|
57
|
+
except Exception as e:
|
58
|
+
print(f"Error fetching {func_name}: {e}")
|
59
|
+
res[func_name] = None
|
60
|
+
|
61
|
+
return res
|