-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_script.py
More file actions
69 lines (54 loc) · 1.74 KB
/
sample_script.py
File metadata and controls
69 lines (54 loc) · 1.74 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
from datetime import datetime
from pprint import pprint
from pyinstagram import OAuth, InstagramApiClient, InstagramJsonClient
CLIENT_ID = ""
CLIENT_SECRET = ""
REDIRECT_URI = ""
# AUTENTICAZIONE
auth = OAuth(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
authorization_redirect_uri=REDIRECT_URI,
scopes=("basic", "public_content")
)
print(auth.get_request_url())
code = input("Inserisci il codice ricevuto: ")
auth.get_access_token(code)
app = InstagramApiClient(auth)
# RECENT MEDIA - LAST 10
media = app.get_by_user(count=3)
for m in media:
print(m.get('caption', {}).get('text', "Senza Titolo"))
print("Postato il {}\n".format(datetime.fromtimestamp(
int(m['created_time'])
).strftime('%Y-%m-%d %H:%M:%S')))
# SEARCH by HASHTAG
media = app.get_by_hashtag("salento")
for m in media:
print(m['caption'].get('text'))
print("Likes: {}".format(m['likes']['count']))
tags = app.search_for_tag("developer", count=3)
for tag, count in tags.items():
print("{0}\t{1}".format(tag, count))
app = InstagramJsonClient()
media = app.get_by_user("nasa")
print("L'utente {utente} ha postato {count} media (immagini o video).".format(
utente=next(iter(media), {}).get('user', {}).get('full_name', "maxmara"),
count=len(media)
))
print("Numero totale di likes: {}".format(
sum(m['likes']['count'] for m in media)
))
app = InstagramJsonClient()
media = app.get_by_user("cern", count=1)
pprint(media[0])
media = app.get_by_hashtag("milanofashionweek")
for m in media:
print(m.json['display_src'])
app = InstagramJsonClient()
media = app.get_by_hashtag("mfw", count=1, top_posts=False)[0]
print(media.caption)
print(media.created_at)
print(media.code)
pprint(app.get_by_media_codes(media.code))