Created
January 28, 2021 01:51
-
-
Save deguchi/35d385400523d3e7d661a5ba37bc04d3 to your computer and use it in GitHub Desktop.
instagramのデータ変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import datetime | |
import shutil | |
f = open('./instagram_ source_data/media.json', 'r') | |
data = json.load(f) | |
photos = data['photos'] | |
for photo in photos: | |
taken_at = photo['taken_at'] | |
tdatetime = datetime.datetime.strptime(taken_at, '%Y-%m-%dT%H:%M:%S%z') | |
if tdatetime.year==2020: | |
print(photo['caption']) | |
shutil.copy('./instagram_ source_data/'+photo['path'], './data/%s-%s-%s.jpg' % (tdatetime.year, tdatetime.month, tdatetime.day)) | |
with open('./data/%s-%s-%s.txt' % (tdatetime.year, tdatetime.month, tdatetime.day), 'w') as f: | |
f.write(photo['caption']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment