-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventRegistryAPI.py
41 lines (30 loc) · 1.29 KB
/
eventRegistryAPI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Event registry
from eventregistry import *
from datetime import datetime, timedelta
import pandas as pd
def get_News_EventRegistry(keywords):
er = EventRegistry(apiKey = "Event Registry Key")
now = datetime.now()
columns = ["title", "link", "pubDate", "content"]
df = pd.DataFrame(columns=columns)
# Ein Tag zurück
date_start = now - timedelta(days=1)
date_start_formatted = date_start.strftime("%Y-%m-%d")
# get the USA URI
#usUri = er.getLocationUri("USA") # = http://en.wikipedia.org/wiki/United_States
#gerUri = "http://en.wikipedia.org/wiki/Germany"
q = QueryArticlesIter(
keywords = QueryItems.OR(keywords),
dataType = ["news", "blog"],
dateStart=date_start_formatted,
isDuplicateFilter="skipDuplicates",
lang=["eng", "deu"])
columns = ["Title", "Date", "Text", "Link"]
df = pd.DataFrame(columns=columns)
# obtain at most 500 newest articles or blog posts, remove maxItems to get all
for art in q.execQuery(er, sortBy = "date", maxItems = 200):
df = pd.concat([df, pd.DataFrame({"Title": [art["title"]], "Date": [art["date"]], "Text": [art["body"]], "Link": [art["url"]]})], ignore_index=True)
return df
"""
df = get_News_EventRegistry(["Ai Agent", "MemGPT"])
"""