-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollowed.py
47 lines (40 loc) · 1.48 KB
/
followed.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
import json
import webbrowser
import csv
import subprocess
import os
# JSONファイル読み込み
with open('following.json') as json_open_following, open('followers.json') as json_open_followers:
json_load_following = json.load(json_open_following)
json_load_followers = json.load(json_open_followers)
# 各リスト初期化
list_following = []
list_followers = []
list_diff = [[]]
# Instagramのユーザーネーム取得
for json_key_following in json_load_following['relationships_following']:
list_following.append(json_key_following['string_list_data'][0]['value'])
for json_key_followers in json_load_followers:
list_followers.append(json_key_followers['string_list_data'][0]['value'])
# フォロー中とフォロワーの相違チェック
for elem in list_following:
if elem in list_followers:
# URL作成
url = 'https://instagram.com/' + elem
# リストに追加
list_diff.append([elem, url])
#謎に1つ目の要素が空でできてしまうので削除(おそらくどこかが悪い)
del list_diff[0]
# csvファイルに書き込み
with open('followed.csv', 'w') as csv_open:
csv_write = csv.writer(csv_open)
csv_write.writerow(['ID ', 'URL'])
csv_write.writerows(list_diff)
#csvファイルを開く(OS別)
try:
if os.name == "nt":
subprocess.Popen(['open', 'followed.csv'], shell=True)
elif os.name == "posix":
subprocess.Popen(['open', 'followed.csv'])
except:
print("can't open csv file.")