-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
99 lines (74 loc) · 2.73 KB
/
app.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
import json
import instagrapi
from instagrapi import Client
client = Client()
username = 'gad_cbflicks'
password = 'gusd410!'
client.login(username, password)
user_id = client.user_id_from_username(username)
print('Logged in')
def listDir(dir):
fileNames = os.listdir(dir)
fileLocations = []
for fileName in fileNames:
filePath = os.path.abspath(os.path.join(dir, fileName))
fileLocations.append(filePath)
return fileLocations
def listandpostDir(dir):
fileNames = os.listdir(dir)
fileLocations = []
for fileName in fileNames:
filePath = os.path.abspath(os.path.join(dir, fileName))
client.photo_upload_to_story(filePath)
print('posted photo: ' + filePath)
fileLocations.append(filePath)
print('completed :' + dir)
return fileLocations
def save_array_as_json(arr, filename):
with open(filename, 'w') as file:
json.dump(arr, file)
save_array_as_json(listDir(r'H:\My Drive\CB FLICKS'), 'newfolders.json')
save_array_as_json([story.pk for story in client.user_stories(user_id)], 'oldstories.json')
def isthere_a_new_folder():
with open('pastfolders.json') as f:
pastfolders = json.load(f)
with open('newfolders.json') as f:
newfolders = json.load(f)
for folder in newfolders:
if folder not in pastfolders:
print('new folder found ')
return True
return False
def what_is_the_new_folder():
with open('pastfolders.json') as f:
pastfolders = json.load(f)
with open('newfolders.json') as f:
newfolders = json.load(f)
for folder in newfolders:
if folder not in pastfolders:
print('new folder found ' + folder)
return folder
def compare_json(file_name):
# Read in the new JSON file
with open(file_name, 'r') as f:
new_data = json.load(f)
# Read in the old JSON file
with open('oldstories.json', 'r') as f:
old_data = json.load(f)
# Create a list to store any new objects that are not in the old file
new_objects = []
# Iterate over the new data and check if each object is in the old file
for obj in new_data:
if obj not in old_data:
new_objects.append(obj)
# Return the list of new objects
return new_objects
# if(isthere_a_new_folder()):
print('--------------------THERE IS A NEW FOLDER FOUND!!!!!! UPLOADING IMAGES TO INSTAGRAM STORY --------------------')
listandpostDir(r'H:\My Drive\CB FLICKS\4. RALLY BOYS')
# client.highlight_create(r'4. RALLY BOYS', [story.pk for story in client.user_stories(user_id)])
save_array_as_json(listDir(r'H:\My Drive\CB FLICKS'), 'pastfolders.json')
print('reset folders')
client.logout()
print('logged out')