-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.py
More file actions
53 lines (40 loc) · 1.56 KB
/
Copy pathscript2.py
File metadata and controls
53 lines (40 loc) · 1.56 KB
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
import mediacloud.api, json, datetime
# ID KEYWORDS AND KEY TO BE ADDED HERE
my_key = 'c803be725711cdedd89941f2ff63a95c07457583f0ed355e50b58fc4d0ca3969'
value1 = 'iphone'
value2 = 'Colombia'
media_Id = 'AND media_id:'+(str(1))
no_of_stories = 1
from_date_start = datetime.date(2019,1,1)
till_date_end = datetime.date(2020,1,1)
###################
def feeds(my_key,value1,value2,media_Id,no_of_stories,from_date_start,till_date_end):
mc = mediacloud.api.MediaCloud(my_key)
fetch_size = 50
stories = []
last_processed_stories_id = 0
while len(stories) < no_of_stories:
fetched_stories = mc.storyList(value1+' AND "'+value2+'" ',
solr_filter=mc.dates_as_query_clause(from_date_start,till_date_end),
last_processed_stories_id=last_processed_stories_id, rows= fetch_size)
stories.extend(fetched_stories)
if len( fetched_stories) < fetch_size:
break
last_processed_stories_id = stories[-1]['processed_stories_id']
return stories
stories = feeds(my_key,value1,value2,media_Id,no_of_stories,from_date_start,till_date_end)
file1 = open(str(value1)+'_'+str(value2)+'_feeds.txt','w')
count = 1
for i in stories:
print(str(count)+ '. '+ i['url'])
try:
file1.write( str(count)+ '. '+ i['url'])
file1.write(' \n ')
# print(str(key) + " is --- -- " + str(value))
count = count + 1
except:
pass
file1.write("____________________")
file1.write('\n ')
file1.write('\n ')
file1.close()