-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
43 lines (34 loc) · 1.22 KB
/
main.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
import time
from InstagramAPI import InstagramAPI
from config import config
from userclass import User
from sqlclass import Sql
influencer_id_list = config.get('influencer_id_list')
def check_api(current_api):
return current_api
def crawl_influencer_followings(sql, api):
for i, influencer_id in enumerate(influencer_id_list):
size = len(influencer_id_list)
print('------ Influencer {}/{} ------'.format(i+1, size))
user = User(user_id=influencer_id, sql=sql, api=check_api(current_api=api))
print(user)
print()
if user.following_count < config.get('max_followings'):
user.get_and_save_user_followings()
print()
if __name__ == '__main__':
# define sql connection
sql = Sql(
user=config.get('postgres_user'),
password=config.get('postgres_password'),
database=config.get('postgres_database')
)
# define instagram connection
print('Connect to Instagram')
api = InstagramAPI(username=config.get('ig_username'), password=config.get('ig_password'))
api.login()
time.sleep(5)
# crawl instagram followings
print('Crawl instagram followings...')
print()
crawl_influencer_followings(sql=sql, api=api)