Skip to content

Instantly share code, notes, and snippets.

@deguchi
Created January 28, 2021 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deguchi/35d385400523d3e7d661a5ba37bc04d3 to your computer and use it in GitHub Desktop.
Save deguchi/35d385400523d3e7d661a5ba37bc04d3 to your computer and use it in GitHub Desktop.
instagramのデータ変換
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