Skip to content

Instantly share code, notes, and snippets.

@rahulbot
Created March 12, 2018 18:14
Show Gist options
  • Save rahulbot/6371c35677655305d2988e77f7b3af05 to your computer and use it in GitHub Desktop.
Save rahulbot/6371c35677655305d2988e77f7b3af05 to your computer and use it in GitHub Desktop.
mc_random_sources_from_collecitons
def media_with_tag(tags_id, cached=False):
more_media = True
all_media = []
max_media_id = 0
while more_media:
media = mc.mediaList(tags_id=tags_id, last_media_id=max_media_id, rows=100)
all_media = all_media + media
if len(media) > 0:
max_media_id = media[len(media) - 1]['media_id']
more_media = len(media) != 0
return all_media
random_sources = []
tags = [9139487, # us new top pew
# partisan retweet
9360520,
9360521,
9360522,
9360523,
9360524,
# countries
34412146, # france
34412118, # india
34412202, # ghana
34412358, # colombia
]
for t in tags:
tag = mc.tag(t)
media_list = media_with_tag(t)
random_sources += random.sample(media_list, 5)
with open('random-sources.csv', 'w') as csvfile:
spamwriter = csv.writer(csvfile)
spamwriter.writerow(['media_id', 'url'])
for m in random_sources:
spamwriter.writerow([str(m['media_id']), m['url']])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment