import feedparser
import ssl
#National Variables
dict_nations = {'UNITED_STATES' : 'p1','ARGENTINA': 'p30', 'AUSTRALIA': 'p8', 'AUSTRIA': 'p44', 'BELGIUM': 'p41', 'BRAZIL': 'p18', 'CANADA': 'p13', 'CHILE': 'p38', 'COLOMBIA': 'p32', 'CZECHIA': 'p43', 'DENMARK': 'p49', 'EGYPT': 'p29', 'FINLAND': 'p50', 'FRANCE': 'p16', 'GERMANY': 'p15', 'GREECE': 'p48', 'HONG_KONG': 'p10', 'HUNGARY': 'p45', 'INDIA': 'p3', 'INDONESIA': 'p19', 'IRELAND': 'p54', 'ISRAEL': 'p6', 'ITALY': 'p27', 'JAPAN': 'p4', 'KENYA': 'p37', 'MALAYSIA': 'p34', 'MEXICO': 'p21', 'NETHERLANDS': 'p17', 'NEW_ZEALAND': 'p53', 'NIGERIA': 'p52', 'NORWAY': 'p51', 'PHILIPPINES': 'p25', 'POLAND': 'p31', 'PORTUGAL': 'p47', 'ROMANIA': 'p39', 'RUSSIA': 'p14', 'SAUDI_ARABIA': 'p36', 'SINGAPORE': 'p5', 'SOUTH_AFRICA': 'p40', 'SOUTH_KOREA': 'p23', 'SPAIN': 'p26', 'SWEDEN': 'p42', 'SWITZERLAND': 'p46', 'TAIWAN': 'p12', 'THAILAND': 'p33', 'TURKEY': 'p24', 'UKRAINE': 'p35', 'UNITED_KINGDOM': 'p9', 'VIETNAM': 'p28',
}
# EXAMPLE SEARCH SYNTAX
# United States:
# https://trends.google.com/trends/hottrends#pn=p1
# United States RSS:
# https://trends.google.com/trends/hottrends/atom/feed?pn=p1
# United Kingdom:
# https://trends.google.com/trends/hottrends#pn=p9
# United Kingdom RSS:
# https://trends.google.com/trends/hottrends/atom/feed?pn=p9
TRENDING_URL = 'http://www.google.com/trends/hottrends/atom/feed?pn={}'
def hot(feed_url):
"""Returns a list of hit terms via google trends
"""
try:
listing = feedparser.parse(feed_url)['entries']
trends = [item['title'] for item in listing]
return trends
except Exception as e:
print('ERR hot terms failed!', str(e))
return None
if __name__ == "__main__":
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
print(hot(TRENDING_URL.format(dict_nations.get("UNITED_STATES"))))