-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_keywords.py
62 lines (54 loc) · 1.45 KB
/
extract_keywords.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# MAKE SURE TO SOURCE ENV VARS FROM .ENVRC
import time
import tqdm
import pandas as pd
import awswrangler as wr
from ebawsconnect.athena import get_query_results_from_athena
def scrape(word="Mark Zuckerberg"):
query = f"""
SELECT *
FROM dfp_prod_jppol_dsa_shrd.escenic_article
WHERE article_url NOT LIKE '/incoming%'
AND LENGTH(article_body) >= 100
AND (article_title LIKE '%{word}%'
OR article_lead LIKE '%{word}%'
OR article_body LIKE '%{word}%')
"""
out = get_query_results_from_athena(query,
results_file = f"{word}.csv",
to_df = True,
force_query = True,
profile_name = "jppol-dfp")
print("Word")
out["keyword"] = word
return out
#t1 = time.time()
#out = scrape("Mark Zuckerberg")
#t2 = time.time()
keywords = ["Mark Zuckerberg"
, "Sheryl Sandberg"
, "Jeff Bezos"
, "Sergei Brin"
, "Larry Page"
, "Sundar Pichai"
, "Tim Cook"
, "Bill Gates"
, "Jack Ma"
, "Elon Musk"
, "Ted Sandros"
, "Jack Dorsey"
, "Margrethe Vestager"
, "Edward Snowden"
, "Christopher Wylie"
, "Peter Thiel"
, "Steve Jobs"
, "Tim Cook"
, "Rick Hastings"
, "Travis Kalanick"]
output = [scrape(keyword) for keyword in tqdm.tqdm(keywords)]
output = pd.concat(output, ignore_index=True)
wr.s3.to_csv(
output,
path="s3://externalresearch/persons.csv",
index=True
)