forked from colorscream/garyvee_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgaryvee.py
120 lines (82 loc) · 3.27 KB
/
garyvee.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
100
101
102
103
104
105
106
107
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import random
import sys
import time
class GaryVee:
username = 'garyveedollareighty'
password = 'dollareighty'
hashtags = [
'wanderlust', 'travels', 'travel', 'explore', 'exploring',
'vacation', 'adventure', 'holiday', 'holidays', 'instatravel',
]
comments = [
'Your posts are amazing', 'Amazing work. Keep going!', 'Your photos are magnificent',
'Your work fascinates me!', 'I like how you put your posts together', 'Great job',
'What a really nice photo, great job!', 'Well done!', 'Your posts are amazing',
]
links = []
price = 0.0
def __init__(self):
self.browser = webdriver.Firefox()
self.login()
self.hustle()
def login(self):
self.browser.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
time.sleep(2)
username_field = self.browser.find_element_by_xpath("//input[@name='username']")
username_field.clear()
username_field.send_keys(self.username)
time.sleep(1)
password_field = self.browser.find_element_by_xpath("//input[@name='password']")
password_field.clear()
password_field.send_keys(self.password)
time.sleep(1)
login_button = self.browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()
time.sleep(2)
def hustle(self):
self.getTopPosts()
self.execute()
self.finalize()
def getTopPosts(self):
for hashtag in self.hashtags:
self.browser.get('https://www.instagram.com/explore/tags/' + hashtag +'/')
time.sleep(2)
links = self.browser.find_elements_by_tag_name('a')
condition = lambda link: '.com/p/' in link.get_attribute('href')
valid_links = list(filter(condition, links))
for i in range(0, 9):
link = valid_links[i].get_attribute('href')
if link not in self.links:
self.links.append(link)
def execute(self):
for link in self.links:
self.browser.get(link)
time.sleep(1)
self.browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
self.comment()
time.sleep(2)
self.like()
self.price += 0.02
sleeptime = random.randint(18, 28)
time.sleep(sleeptime)
def comment(self):
comment_input = lambda: self.browser.find_element_by_tag_name('textarea')
comment_input().click()
comment_input().clear()
comment = random.choice(self.comments)
for letter in comment:
comment_input().send_keys(letter)
delay = random.randint(1, 7) / 30
time.sleep(delay)
comment_input().send_keys(Keys.RETURN)
def like(self):
like_button = lambda: self.browser.find_element_by_xpath('//span[@class="glyphsSpriteHeart__outline__24__grey_9 u-__7"]')
like_button().click()
def finalize(self):
print 'You gave $' + string(self.price) + ' back to the community.'
self.browser.close()
sys.exit()
garyVee = GaryVee()