Skip to content

Instantly share code, notes, and snippets.

@tikseniia
Created February 4, 2019 23:53
Show Gist options
  • Save tikseniia/9ae5e00262a0460423b4391c23cf9b92 to your computer and use it in GitHub Desktop.
Save tikseniia/9ae5e00262a0460423b4391c23cf9b92 to your computer and use it in GitHub Desktop.
Get post location
with open('posts.json', 'r') as f:
arr = json.loads(f.read()) # load json data from previous step
locations = []
for item in arr:
shortcode = item['shortcode']
url = "https://www.instagram.com/p/{0}/?__a=1".format(shortcode)
r = requests.get(url)
data = json.loads(r.text)
try:
location = data['graphql']['shortcode_media']['location']['name'] # get location for a post
except:
location = '' # if location is NULL
locations.append({'shortcode': shortcode, 'location': location})
with open('locations.json', 'w') as outfile:
json.dump(locations, outfile) # save to json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment