Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.00 KB | None | 0 0
  1. from requests import get as goto
  2. import requests
  3. import time
  4. from Tkinter import *
  5. from threading import *
  6. import ttk
  7. from lxml.html import fromstring
  8. import sys
  9. import tweepy, time, sys,requests,Queue
  10. CONSUMER_KEY = '0Z3CiBRGeIa7Oso9OV9U6pIqC'#keep the quotes, replace this with your consumer key
  11. CONSUMER_SECRET = 'YhqXbFBKkYbxv3cqLoZ60ksSR1krMZuFaSmH7TzbxoMt6qGtUB'#keep the quotes, replace this with your consumer secret key
  12. ACCESS_KEY = '761672950403698690-ys68A0iXAzXhlErcrCy4poUhOcaKKYW'#keep the quotes, replace this with your access token
  13. ACCESS_SECRET = 'p9c9wl04V0v9hkvKzw0FcVzAQQRxcUjqHNMiLfogiKYic'#keep the quotes, replace this with your access token secret
  14. auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
  15. auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
  16. global api
  17. api = tweepy.API(auth)
  18. queuee = Queue.Queue()
  19. global run1
  20. run1 = False
  21. global tasksrun
  22. tasksrun=0
  23.  
  24. def star(store,nothing):
  25. Monitor(store)
  26. class Monitor():
  27. def __init__(self,store):
  28. global tasksrun
  29. tasksrun +=1
  30. Thread(target=self.check1(store,tasksrun)).start()
  31.  
  32. def check1(self,StoreLink,tasksruned_):
  33.  
  34. s = requests.Session()
  35. resp = s.get(StoreLink+'/sitemap_products_1.xml')
  36. self.items = []
  37. tree11 = fromstring(resp.content)
  38. url_tags = tree11.xpath("//url[image]")
  39. data = [e.xpath("./loc/text()")[0] for e in url_tags]
  40. for item in data:
  41. self.items.append(item)
  42. Thread(target=self.Scrape(StoreLink,tasksruned_,resp.content)).start()
  43. def process_queue(self):
  44. try:
  45. item = queuee.get(0)
  46. # Show result of the task if needed
  47. except Queue.Empty:
  48. process_queue()
  49.  
  50.  
  51. def Scrape(self,StoreLink,tasksruned_,OLDTREE):
  52. while True:
  53. try:
  54. respe = requests.get(StoreLink+'/sitemap_products_1.xml')
  55. if respe.content == OLDTREE:
  56. del respe
  57. time.sleep(5)
  58. else:
  59.  
  60.  
  61. OGLINK = StoreLink
  62. OLDTREE = respe.content
  63.  
  64. s = requests.Session()
  65. resp = s.get(StoreLink+'/sitemap_products_1.xml')
  66.  
  67. NewItem = False
  68. tree11 = fromstring(resp.content)
  69. url_tags = tree11.xpath("//url[image]")
  70. data = [e.xpath("./loc/text()")[0] for e in url_tags]
  71. senddatae = []
  72. for item in data:
  73. if item not in self.items:
  74. OLDTREE = resp.content
  75. itemlink = item
  76. itemlinkx = (item+".xml")
  77. self.items.append(itemlink)
  78. getitem = s.get(itemlinkx)
  79. OLDTREE = getitem.content
  80. tree12 = fromstring(getitem.content)
  81. variants = tree12.xpath("//variants[@type='array']//id[@type='integer']//text()")
  82. option1 = tree12.xpath("//variants[@type='array']//option1//text()")
  83. option2 = tree12.xpath("//variants[@type='array']//option2//text()")
  84. option3 = tree12.xpath("//variants[@type='array']//option3//text()")
  85. inventory = tree12.xpath("//variants[@type='array']//inventory-quantity//text()")
  86. price = tree12.xpath("//variants[@type='array']//price//text()")
  87. getot = len(variants)
  88. optiones =[]
  89. geto =0
  90. inv =0
  91. for item in variants:
  92. senddatae.append(item)
  93. if geto<getot:
  94. try:
  95. senddatae.append((option1[geto]))
  96. optiones.append((option1[geto]))
  97. except:
  98. pass
  99. try:
  100. senddatae.append((option2[geto]))
  101. optiones.append((option2[geto]))
  102. except:
  103. pass
  104. try:
  105. senddatae.append((option3[geto]))
  106. optiones.append((option3[geto]))
  107. except:
  108. pass
  109. try:
  110. senddatae.append(("Inventory : "+inventory[geto]))
  111. inv +=int(inventory[geto])
  112. except:
  113. pass
  114. geto+=1
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122. title = s.get(itemlink+".js")
  123. i = title.content.split("title")
  124. ii = i[1].split('"')
  125. newitem = ii[2]
  126.  
  127.  
  128.  
  129. msg = (time.strftime("%c")+"\n"+newitem+"\n"+itemlink+'\nPrice - '+str(price[0])+"\n Total Inventory | "+str(inv))
  130. api.update_status(msg)
  131. if 1<2:
  132. msg = (time.strftime("%c")+"\n"+newitem+"\n"+itemlink+'\nPrice - '+str(price[0])+"\n Total Inventory | "+str(inv)+"\n"+str(senddatae))
  133. for i in sendem:
  134. import smtplib
  135. fromaddr = 'cookifyscraper@gmail.com'
  136. toaddrs = i
  137. headers = "\r\n".join([
  138. "subject: " + "SCRAPER "])
  139. content = msg
  140. username = 'cookifyscraper@gmail.com'
  141. password = 'CookifyScraper11'
  142. server = smtplib.SMTP('smtp.gmail.com:587')
  143. server.starttls()
  144. server.login(username,password)
  145. server.sendmail(fromaddr, toaddrs, content)
  146. server.quit()
  147. tree11.clear
  148. Thread(target=self.ScrapeChange,args =(itemlink,senddatae,inv,price[0],optiones,newitem,OLDTREE)).start()
  149. try:
  150. print "###################"+"\nNEW ITEM - "+newitem+"\n"+str(senddatae)+"\n###################"
  151. except:
  152. print "###################"+"\nNEW ITEM - "+newitem+"\n###################"
  153. del msg,newitem,s,tree11
  154. time.sleep(5)
  155. except Exception as e:
  156. print e
  157.  
  158.  
  159.  
  160.  
  161. def ScrapeChange(self,itemlink,info,inv,oldprice,optiones,title,OLDTREEI):
  162. while True:
  163. try:
  164. getitem = requests.get(itemlink+".xml")
  165. if OLDTREEI == getitem.content:
  166.  
  167. del getitem
  168. time.sleep(5)
  169. else:
  170. print "CHANGE!"
  171. sendvar = False
  172. s = requests.Session()
  173. getitem = s.get(itemlink+".xml")
  174. OLDTREEI = getitem.content
  175. tree12 = fromstring(getitem.content)
  176. sendd = info
  177. strsend=""
  178. sendo = []
  179. inve = 0
  180.  
  181. oldprices = str(oldprice).split(".")
  182. oldpri = oldprices[0]
  183. if 1<2:
  184. variants = tree12.xpath("//variants[@type='array']//id[@type='integer']//text()")
  185. sendd.append(variants)
  186. sendo.append(variants)
  187. option1 = tree12.xpath("//variants[@type='array']//option1//text()")
  188. for item in option1:
  189. if item not in optiones:
  190. sendo.append(item)
  191. api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
  192. sendd.append(item)
  193. optiones.append(item)
  194. NewItem =True
  195. for i in sendem:
  196. import smtplib
  197. fromaddr = 'cookifyscraper@gmail.com'
  198. toaddrs = i
  199. headers = "\r\n".join([
  200. "subject: " + "SCRAPER "])
  201. msg = ("GOO \n "+itemlink)
  202. content = msg
  203. username = 'cookifyscraper@gmail.com'
  204. password = 'CookifyScraper11'
  205. server = smtplib.SMTP('smtp.gmail.com:587')
  206. server.starttls()
  207. server.login(username,password)
  208. server.sendmail(fromaddr, toaddrs, content)
  209. server.quit()
  210. sendvar = True
  211.  
  212.  
  213.  
  214. option2 = tree12.xpath("//variants[@type='array']//option2//text()")
  215. for item in option2:
  216. if item not in optiones:
  217. sendo.append(item)
  218. api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
  219. sendd.append(item)
  220. optiones.append(item)
  221. NewItem =True
  222. for i in sendem:
  223. import smtplib
  224. fromaddr = 'cookifyscraper@gmail.com'
  225. toaddrs = i
  226. headers = "\r\n".join([
  227. "subject: " + "SCRAPER "])
  228. msg = ("GOO \n "+itemlink)
  229. content = msg
  230. username = 'cookifyscraper@gmail.com'
  231. password = 'CookifyScraper11'
  232. server = smtplib.SMTP('smtp.gmail.com:587')
  233. server.starttls()
  234. server.login(username,password)
  235. server.sendmail(fromaddr, toaddrs, content)
  236. server.quit()
  237. sendvar = True
  238. option3 = tree12.xpath("//variants[@type='array']//option3//text()")
  239. for item in option3:
  240. if item not in optiones:
  241. sendo.append(item)
  242. api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
  243. sendd.append(item)
  244. optiones.append(item)
  245. NewItem =True
  246. for i in sendem:
  247. import smtplib
  248. fromaddr = 'cookifyscraper@gmail.com'
  249. toaddrs = i
  250. headers = "\r\n".join([
  251. "subject: " + "SCRAPER "])
  252. msg = ("GOO \n "+itemlink)
  253. content = msg
  254. username = 'cookifyscraper@gmail.com'
  255. password = 'CookifyScraper11'
  256. server = smtplib.SMTP('smtp.gmail.com:587')
  257. server.starttls()
  258. server.login(username,password)
  259. server.sendmail(fromaddr, toaddrs, content)
  260. server.quit()
  261. sendvar = True
  262. inventory = tree12.xpath("//variants[@type='array']//inventory-quantity//text()")
  263. for item in inventory :
  264. if item > int(inv):
  265. sendo.append(item)
  266. api.update_status("RESTOCK \n"+title+"\n"+itemlink)
  267. sendd.append(item)
  268. optiones.append(item)
  269. NewItem =True
  270. for i in sendem:
  271. import smtplib
  272. fromaddr = 'cookifyscraper@gmail.com'
  273. toaddrs = i
  274. headers = "\r\n".join([
  275. "subject: " + "SCRAPER "])
  276. msg = ("GOO \n "+itemlink)
  277. content = msg
  278. username = 'cookifyscraper@gmail.com'
  279. password = 'CookifyScraper11'
  280. server = smtplib.SMTP('smtp.gmail.com:587')
  281. server.starttls()
  282. server.login(username,password)
  283. server.sendmail(fromaddr, toaddrs, content)
  284. server.quit()
  285. sendvar = True
  286. price = tree12.xpath("//variants[@type='array']//price//text()")
  287. for item in price:
  288. if item < int(oldpri):
  289. sendo.append(item)
  290. api.update_status("PRICE DROP \n"+title+"\n"+itemlink)
  291. sendd.append(item)
  292. optiones.append(item)
  293. NewItem =True
  294. for i in sendem:
  295. import smtplib
  296. fromaddr = 'cookifyscraper@gmail.com'
  297. toaddrs = i
  298. headers = "\r\n".join([
  299. "subject: " + "SCRAPER "])
  300. msg = ("GOO \n "+itemlink)
  301. content = msg
  302. username = 'cookifyscraper@gmail.com'
  303. password = 'CookifyScraper11'
  304. server = smtplib.SMTP('smtp.gmail.com:587')
  305. server.starttls()
  306. server.login(username,password)
  307. server.sendmail(fromaddr, toaddrs, content)
  308. server.quit()
  309. sendvar = True
  310. cost = item
  311.  
  312.  
  313. if sendvar == True:
  314. for i in sendem:
  315. import smtplib
  316. fromaddr = 'cookifyscraper@gmail.com'
  317. toaddrs = i
  318. headers = "\r\n".join([
  319. "subject: " + "SCRAPER "])
  320. msg = (time.strftime("%c")+title+"\n"+itemlink+"\n"+str(sendo))
  321. print msg
  322. content = msg
  323. username = 'cookifyscraper@gmail.com'
  324. password = 'CookifyScraper11'
  325. server = smtplib.SMTP('smtp.gmail.com:587')
  326. server.starttls()
  327. server.login(username,password)
  328. server.sendmail(fromaddr, toaddrs, content)
  329. server.quit()
  330. tree1.clear()
  331. try:
  332. del s,getitem,sendd,tree1,strsend,inve,oldprices,oldpri,pric,pricee,variantes
  333. except:
  334. pass
  335. time.sleep(5)
  336. except Exception as E:
  337. print E
  338.  
  339.  
  340. global sendem
  341. sendem = []
  342. def goo():
  343. comm = raw_input("Command?")
  344. if "add link" in comm:
  345. sto = comm.split(" ")
  346. storee = sto[2]
  347. storelin = storee
  348. Thread(target=star,args=(storelin,0)).start()
  349. print storee+" Added!"
  350. goo()
  351. if "add email" in comm:
  352. em = comm.split(" ")
  353. sendem.append(em[2])
  354. print "Email - "+em[2]+" Has Been Added!"
  355. goo()
  356. goo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement