def getLikesFromAll(self): babes = usersDB.loadState('babes.pickle') babeArr = list(babes.keys()) posting = usersDB.loadState('postingBabes.pickle') for elem in list(posting.keys()): babeArr.remove(elem) for babe in babeArr: pictures = list(babes[babe].keys()) for picture in pictures: # get all likes likes = self.getPost(picture, self.getLikes, {}) babes[babe][picture] = {"processed": False} babes[babe][picture]["likes"] = likes usersDB.saveState(babes, 'babes.pickle') print('saved babe in DB', babes[babe])
def debug(): posts = usersDB.loadState('uploaded.pickle') babes = list(posts.keys()) i = 0 for babe in babes: try: i += 1 print(posts[babe]["iteration"]) print('babe has already been uploaded') continue except: try: print('new Babe uploading...') post = list(posts[babe].keys())[0] print(post) image = posts[babe][post]["src"] urllib.request.urlretrieve(image, os.getcwd() + f"/0images/0.png") # self.post() posts[babe]["iteration"] = 0 print('delete again') os.remove(os.getcwd() + '/0images/0.png') # usersDB.saveState(posts, 'uploaded.pickle') break except: print("empty user... skipping user") continue
def addPictureSrc(): babes = usersDB.loadState('postingBabes.pickle') babeArr = list(babes.keys()) """ posting = usersDB.loadState('posts.pickle') for elem in list(posting.keys()): babeArr.remove(elem) # babes = list(posting.keys()) print('startValue', babes) """ for babe in babeArr: posts = list(babes[babe].keys()) for post in posts: try: print(babes[babe][post]["src"]) print('already downloaded') break except: babes[babe][post] = {} print('enter loop') try: driver.get(post) sleep(2) src = driver.execute_script(""" return document.getElementsByClassName("_97aPb ")[0].querySelector('img').src """) babes[babe][post]["posted"] = False babes[babe][post]["src"] = src # print(posting[babe]) print(babes[babe][post]) # urllib.request.urlretrieve(src, os.getcwd()+ f"/images/{post}.png") usersDB.saveState(babes, 'posts.pickle') print('SAVED') except: continue
def extractAllUsers(self): posts = usersDB.loadState('users.pickle') links = list(posts.keys()) for link in links: self.driver.switch_to.window(self.driver.window_handles[0]) self.getPost(link, self.getUserHandle) usersDB.saveState(users, 'babes.pickle') print('saved state to file')
def findQualityPicture(self): babes = usersDB.loadState('babes.pickle') babesArr = list(babes.keys()) for babe in babesArr: # from the first page get all pictures and their likes # result result = self.getPost(babe, self.getAllRows, babes[babe]) babes[babe] = result usersDB.saveState(babes, 'babes.pickle') print('final result', babes)
def deFollowUsers(): following = usersDB.loadState('following.pickle') # run once at the end of a day # today = datetime.date.today() today = date(2021, 1, 12) weekBefore = today - datetime.timedelta(days=7) print(weekBefore) try: print('access week ago', following[str(weekBefore)]) for elem in following[str(weekBefore)]: print('deFollow', elem) following[str(weekBefore)].append('defollowed') usersDB.saveState(following, 'following.pickle') except: print('one week has not passed yet')
def test(): babes = usersDB.loadState('babes.pickle') babeArr = list(babes.keys()) print('RESULT LÄNGE', len(babeArr)) print(babeArr.index('https://www.instagram.com/juuleechkaa/')) print(babes[babeArr[87]]) posting = {} print('POSTED', list(posting.keys())) print(len(list(posting.keys()))) n = 0 for babe in babeArr: try: n += 1 print(n) pictures = list(babes[babe].keys()) likesArr = [] obj = {} posting[babe] = {} for picture in pictures: # get all likes likes = babes[babe][picture]["likes"] likesArr.append(likes) obj[likes] = picture likesArr.sort(reverse=True) #print(likesArr) for i in range(3): babes[babe][obj[likesArr[i]]]["passed"] = True posting[babe][obj[likesArr[i]]] = False # print(babes[babe][obj[likesArr[i]]]["passed"]) print('babes sucessfully selected') usersDB.saveState(posting, 'postingBabes.pickle') # print(posting) """ posting.pop(list(posting.keys())[-1], None) print(len(babeArr)) print(list(posting.keys())) print(len(list(posting.keys()))) """ #usersDB.saveState(posting, 'postingBabes.pickle') # usersDB.saveState(posting, 'postingBabes.pickle') except: continue
def getCosts(self, orderID, endID): products = usersDB.loadState('revenue.pickle') self.driver.get('https://printify.com/app/orders/2') difference = endID - orderID sleep(3) i = 0 while i < difference: self.driver.switch_to.window(self.driver.window_handles[0]) stringID = '#' + str(orderID) try: print('processing product', stringID) orderLink = self.driver.execute_script( """ array = document.body.getElementsByTagName('div') let found for (let i = 0 ; i< array.length ; i++){ if(array[i].innerText.substr(0,5) == arguments[0]){found = array[i]; break;} } return found.parentElement.href """, stringID) except: print('stringID not found') orderID += 1 continue self.openProductInNewTab(orderLink) totalCosts = self.driver.execute_script(""" let totalCosts = document.body.getElementsByClassName('order__billing__entry order__billing__total')[0].children[1].innerText.substr(4) return totalCosts """) print(totalCosts) products[orderID]["costs"] = float(totalCosts) # put all prices to orderID orderID += 1 i += 1 usersDB.saveState(products, 'revenue.pickle') print(products) self.driver.close()
def commentAndLike(self, comment, seconds): users = usersDB.loadState('userHQ.pickle') randomList = [k for k, v in users.items() if v == False] print('length of userDB', len(randomList)) random.shuffle(randomList) selected = [] for k in range(0, 200): selected.append(random.choice(randomList)) print('random selected users', selected) n = 0 for k in selected: sleep(seconds) print('processing userList', len(selected)) if n < comment: if users[k] == "PRIVATE": print('useraccount is private') continue if users[k] == True: print('user has already been commented') continue print(k) self.driver.switch_to.window(self.driver.window_handles[0]) sleep(7) self.driver.execute_script("window.open('','_blank');") sleep(2) self.driver.switch_to.window(self.driver.window_handles[1]) sleep(2) self.driver.get("https://instagram.com/" + k + '/') sleep(2) try: self.driver.find_element_by_xpath( '//article[@class="ySN3v"]/div/div/div/div/a/div' ).click() sleep(2) except: print('error', 'weird stuff going on') pass try: #like picture self.driver.execute_script(""" document.querySelector('svg[aria-label="Like"]').parentNode.click() """) # write a comment except: pass try: self.driver.find_element_by_xpath( '//textarea[@class="Ypffh"]').click() except NoSuchElementException: print("This account is private. Flagging as private") users[k] = "PRIVATE" usersDB.saveState(users, 'userHQ.pickle') pass sleep(2) try: self.driver.find_element_by_xpath( '//form[@class="X7cDz"]/textarea').send_keys( "@" + k + " " + random.choice(comments)) sleep(2) self.driver.find_element_by_xpath( '//form[@class="X7cDz"]/textarea').send_keys( Keys.RETURN) sleep(4) try: postButton = self.driver.execute_script(""" let buttons = document.body.getElementsByTagName("button") for (let i = 0; i< buttons.length; i++){ if (buttons[i].textContent == "Post"){ return buttons[i] } } """) postButton.click() sleep(2) print('liked and commented sucessfully') except: print("comment failed") users[k] = True usersDB.saveState(users, 'userHQ.pickle') n += 1 except NoSuchElementException: print(NoSuchElementException) pass self.driver.close() else: print('limit of public comments reached. Exit') break print([k for k, v in users.items() if v == True]) print(selected)
scope = [ "https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive" ] creds = ServiceAccountCredentials.from_json_keyfile_name("creds.json", scope) client = gspread.authorize(creds) sheet = client.open("tutorial").sheet1 # Open the spreadhseet data = sheet.get_all_records() # Get a list of all records print(data) revenue = usersDB.loadState('revenue.pickle') print(revenue) orderIDList = list(revenue.keys()) i = 3 for order in orderIDList: try: insertRow = [order, revenue[order]["price"], revenue[order]["costs"]] except: insertRow = [order, revenue[order]["price"], 0] sheet.insert_row(insertRow, i) i += 1 sleep(2)
def test(): usersDB.loadState('revenue.pickle')