-
Notifications
You must be signed in to change notification settings - Fork 0
/
instaget.py
84 lines (62 loc) · 2.41 KB
/
instaget.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import datetime
import logging
import sqlite3
from statistics import mean
from dbextract import *
from instadownload import *
def get_user_info(api, user_id=None, username=None):
user_id = get_user_id(api, user_id=user_id, username=username)
if not user_id:
return False
user_info = extract_user_info(user_id=user_id)
if not user_info:
if not download_user_info(api, user_id):
return False
user_info = extract_user_info(user_id=user_id)
return user_info
def get_user_followers(api, user_id=None, username=None):
user_id = get_user_id(api, user_id=user_id, username=username)
if not user_id:
return False
followers = extract_user_followers(user_id)
user_info = get_user_info(api, user_id=user_id)
if not user_info:
return False
if not followers or len(followers) < 0.9 * user_info["follower_count"]:
if not download_user_followers(api, user_id):
return False
followers = extract_user_followers(user_id)
return followers
def get_user_followings(api, user_id=None, username=None):
user_id = get_user_id(api, user_id=user_id, username=username)
if not user_id:
return False
followings = extract_user_followings(user_id)
user_info = get_user_info(api, user_id=user_id)
if not user_info:
return False
if not followings or len(followings) < 0.9 * user_info["following_count"]:
if not download_user_followings(api, user_id):
return False
followings = extract_user_followings(user_id)
return followings
def get_user_medias(api, user_id=None, username=None):
user_id = get_user_id(api, user_id=user_id, username=username)
if not user_id:
return False
medias = extract_user_medias(user_id)
if not medias:
if not download_user_medias(api, user_id):
return False
medias = extract_user_medias(user_id)
return medias
def make_user_mipt(user_id):
with dataset.connect() as db:
db["instagram_mipt_users"].upsert(dict(user_id=user_id), ["user_id"])
return True
def make_media_downloaded(media_id, caption, author_id):
with dataset.connect() as db:
db["instagram_posted_medias"].insert(dict(original_media_id=media_id,
caption=caption,
original_author_id=author_id))
return True