-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteem_delegation_control_selenium.py
262 lines (150 loc) · 4.97 KB
/
steem_delegation_control_selenium.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
''' ################################### '''
''' ## steemit delegation control v1 '''
''' ## by Murat Tatar # Mart 2018 '''
''' ################################### '''
import re
import os
import time
import requests
import selenium
from selenium import webdriver as web
from selenium.webdriver.common.keys import Keys
''' #windows '''
from Tkinter import *
''' # bg image '''
from PIL import Image, ImageTk, ImageGrab
#username = raw_input('UserName?: ')
username = 'username'
# select requests or selenium.
# If html element code not seen in page source (ctrl+u)
# mean, air elements created via script, we should Selenium
way = 'sel' # or 'req'
# quick exit
def e():
exit()
# catch the word(s)
def Between(bgn,end,sentence):
b1 = sentence.split(bgn)
b2 = b1[1].split(end)
ar = b2[0]
return ar
# get page source code (like as ctrl+u)
def GetContent(url):
r = requests.get(url)
incontent = r.text
return incontent
def DelegationControl(username):
url = 'https://steemd.com/@'+username
cnt = GetContent(url)
rows = re.findall('\?page=(.*?)">', cnt)
pagenumber = len(rows)+1
# source code has all elements, way = 'req'
# it has not all, way = 'sel'
if way == 'req':
i=1
dlgS=[];
while i<pagenumber+1:
adr = 'https://steemd.com/@'+username+'?page='+str(i)
print adr
inc = GetContent(url)
dlgS.append(inc)
i = i+1
print '\n-------', dlgS
elif way == 'sel':
''' # Call the chromedriver '''
driver = web.Chrome("chromedriver.exe")
''' # set chromedriver window size and position '''
''' # if you get an error about the click location, '''
''' # you should set the pixel location '''
driver.set_window_size(1360, 768)
driver.set_window_position(0,0)
i=1; dhtml='<h3>Delegation Control<h3><br>'
while i<pagenumber+1:
''' # Bring an Chain control address like as SteemD '''
adr = 'https://steemd.com/@'+username+'?page='+str(i)
print adr
driver.get(adr)
driver.implicitly_wait(30)
''' # Wait for driver done '''
time.sleep(3)
''' # find element created via javasctipt that there is NOT in Ctrl + U '''
js_code = '''
b = document.getElementsByTagName('span');
return b
'''
# execute script "in" chrome driver
spns = driver.execute_script(js_code)
x=0; sp_ar=[]
for element in spns:
element_text = element.text
#print x, element_text
sp_ar.append(element_text)
if ' delegate ' in element_text:
print adr
print element_text
dhtml = dhtml + '<a href="'+adr+'">element_text</a><br>'
x= x+1
#print sp_ar
i = i+1
''' # create html '''
if dhtml=='<h3>Delegation Control<h3><br>': dhtml = dhtml + 'Not found Delegation record on steemd.com'
o = open("dhtml.html","w"); o.write(dhtml); o.close()
os.startfile("dhtml.html") # open alert.html
''' ## Window functions ########## '''
def wquit():
global delegationbox
print "exited"
delegationbox.destroy()
e()
def SendtoStrBox(sunu):
var.set(sunu)
def Startd():
username = ReadUser()
print "started"
DelegationControl(username)
def Stopd():
wquit()
def BoxPlace(event):
if userBox.get() == ' UserName?':
userBox.delete(0, "end")
userBox.insert(0, ' ',)
def ReadUser():
buser = userBox.get()
buser = buser.strip()
return buser
''' ## Windows Creating ################### '''
delegationbox = Tk()
delegationbox.iconbitmap(default='ico.ico')
delegationboxTitle = delegationbox.title("Steemit Delegation Control v1.0 -alfa")
en = 530; by = 345
#ekran boyutu ogren
sw = delegationbox.winfo_screenwidth()
sh = delegationbox.winfo_screenheight()
x = (sw-en)/2+7
y = (sh-by)/2-102
go = str(en) + "x" + str(by) + "+" + str(x) + "+" + str(y)
delegationbox.geometry(go)
delegationbox["bg"] = "#15151A"
delegationbox.resizable(width=FALSE, height=FALSE)
photo = PhotoImage(file="back.gif")
label = Label(image=photo)
label.place(x=0, y=0)
userBox = Entry(delegationbox, font=("Tahoma",12), fg="#70e4b8", bg="#15151A")
userBox.place(x=130,y=60,height=38, width=145)
userBox.insert(0, ' UserName?')
userBox.bind('<FocusIn>', BoxPlace)
symimage1 = ImageTk.PhotoImage(file="start.gif")
startBtn = Button(image=symimage1,command= Startd); startBtn.place(x=290, y=60)
var = StringVar()
var.set('Enter your UserName and click to Start. (be patient)')
strBox = Label(delegationbox, textvariable = var,
font=("Tahoma",11), fg="#70e4b8", bg="#15151A")
strBox.place(x=0, y=305,height=37, width=530)
''' ## bring to front '''
def bringFront():
delegationbox.lift()
delegationbox.attributes('-topmost', 1)
#delegationbox.attributes('-topmost', 0)
bringFront()
while True:
delegationbox.mainloop()