Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from requests import get as goto
- import requests
- import time
- from Tkinter import *
- from threading import *
- import ttk
- from lxml.html import fromstring
- import sys
- import tweepy, time, sys,requests,Queue
- CONSUMER_KEY = '0Z3CiBRGeIa7Oso9OV9U6pIqC'#keep the quotes, replace this with your consumer key
- CONSUMER_SECRET = 'YhqXbFBKkYbxv3cqLoZ60ksSR1krMZuFaSmH7TzbxoMt6qGtUB'#keep the quotes, replace this with your consumer secret key
- ACCESS_KEY = '761672950403698690-ys68A0iXAzXhlErcrCy4poUhOcaKKYW'#keep the quotes, replace this with your access token
- ACCESS_SECRET = 'p9c9wl04V0v9hkvKzw0FcVzAQQRxcUjqHNMiLfogiKYic'#keep the quotes, replace this with your access token secret
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
- global api
- api = tweepy.API(auth)
- queuee = Queue.Queue()
- global run1
- run1 = False
- global tasksrun
- tasksrun=0
- def star(store,nothing):
- Monitor(store)
- class Monitor():
- def __init__(self,store):
- global tasksrun
- tasksrun +=1
- Thread(target=self.check1(store,tasksrun)).start()
- def check1(self,StoreLink,tasksruned_):
- s = requests.Session()
- resp = s.get(StoreLink+'/sitemap_products_1.xml')
- self.items = []
- tree11 = fromstring(resp.content)
- url_tags = tree11.xpath("//url[image]")
- data = [e.xpath("./loc/text()")[0] for e in url_tags]
- for item in data:
- self.items.append(item)
- Thread(target=self.Scrape(StoreLink,tasksruned_,resp.content)).start()
- def process_queue(self):
- try:
- item = queuee.get(0)
- # Show result of the task if needed
- except Queue.Empty:
- process_queue()
- def Scrape(self,StoreLink,tasksruned_,OLDTREE):
- while True:
- try:
- respe = requests.get(StoreLink+'/sitemap_products_1.xml')
- if respe.content == OLDTREE:
- del respe
- time.sleep(5)
- else:
- OGLINK = StoreLink
- OLDTREE = respe.content
- s = requests.Session()
- resp = s.get(StoreLink+'/sitemap_products_1.xml')
- NewItem = False
- tree11 = fromstring(resp.content)
- url_tags = tree11.xpath("//url[image]")
- data = [e.xpath("./loc/text()")[0] for e in url_tags]
- senddatae = []
- for item in data:
- if item not in self.items:
- OLDTREE = resp.content
- itemlink = item
- itemlinkx = (item+".xml")
- self.items.append(itemlink)
- getitem = s.get(itemlinkx)
- OLDTREE = getitem.content
- tree12 = fromstring(getitem.content)
- variants = tree12.xpath("//variants[@type='array']//id[@type='integer']//text()")
- option1 = tree12.xpath("//variants[@type='array']//option1//text()")
- option2 = tree12.xpath("//variants[@type='array']//option2//text()")
- option3 = tree12.xpath("//variants[@type='array']//option3//text()")
- inventory = tree12.xpath("//variants[@type='array']//inventory-quantity//text()")
- price = tree12.xpath("//variants[@type='array']//price//text()")
- getot = len(variants)
- optiones =[]
- geto =0
- inv =0
- for item in variants:
- senddatae.append(item)
- if geto<getot:
- try:
- senddatae.append((option1[geto]))
- optiones.append((option1[geto]))
- except:
- pass
- try:
- senddatae.append((option2[geto]))
- optiones.append((option2[geto]))
- except:
- pass
- try:
- senddatae.append((option3[geto]))
- optiones.append((option3[geto]))
- except:
- pass
- try:
- senddatae.append(("Inventory : "+inventory[geto]))
- inv +=int(inventory[geto])
- except:
- pass
- geto+=1
- title = s.get(itemlink+".js")
- i = title.content.split("title")
- ii = i[1].split('"')
- newitem = ii[2]
- msg = (time.strftime("%c")+"\n"+newitem+"\n"+itemlink+'\nPrice - '+str(price[0])+"\n Total Inventory | "+str(inv))
- api.update_status(msg)
- if 1<2:
- msg = (time.strftime("%c")+"\n"+newitem+"\n"+itemlink+'\nPrice - '+str(price[0])+"\n Total Inventory | "+str(inv)+"\n"+str(senddatae))
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- tree11.clear
- Thread(target=self.ScrapeChange,args =(itemlink,senddatae,inv,price[0],optiones,newitem,OLDTREE)).start()
- try:
- print "###################"+"\nNEW ITEM - "+newitem+"\n"+str(senddatae)+"\n###################"
- except:
- print "###################"+"\nNEW ITEM - "+newitem+"\n###################"
- del msg,newitem,s,tree11
- time.sleep(5)
- except Exception as e:
- print e
- def ScrapeChange(self,itemlink,info,inv,oldprice,optiones,title,OLDTREEI):
- while True:
- try:
- getitem = requests.get(itemlink+".xml")
- if OLDTREEI == getitem.content:
- del getitem
- time.sleep(5)
- else:
- print "CHANGE!"
- sendvar = False
- s = requests.Session()
- getitem = s.get(itemlink+".xml")
- OLDTREEI = getitem.content
- tree12 = fromstring(getitem.content)
- sendd = info
- strsend=""
- sendo = []
- inve = 0
- oldprices = str(oldprice).split(".")
- oldpri = oldprices[0]
- if 1<2:
- variants = tree12.xpath("//variants[@type='array']//id[@type='integer']//text()")
- sendd.append(variants)
- sendo.append(variants)
- option1 = tree12.xpath("//variants[@type='array']//option1//text()")
- for item in option1:
- if item not in optiones:
- sendo.append(item)
- api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
- sendd.append(item)
- optiones.append(item)
- NewItem =True
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = ("GOO \n "+itemlink)
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- sendvar = True
- option2 = tree12.xpath("//variants[@type='array']//option2//text()")
- for item in option2:
- if item not in optiones:
- sendo.append(item)
- api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
- sendd.append(item)
- optiones.append(item)
- NewItem =True
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = ("GOO \n "+itemlink)
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- sendvar = True
- option3 = tree12.xpath("//variants[@type='array']//option3//text()")
- for item in option3:
- if item not in optiones:
- sendo.append(item)
- api.update_status("RESTOCK SIZE: "+item+ "\n"+title+"\n"+itemlink)
- sendd.append(item)
- optiones.append(item)
- NewItem =True
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = ("GOO \n "+itemlink)
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- sendvar = True
- inventory = tree12.xpath("//variants[@type='array']//inventory-quantity//text()")
- for item in inventory :
- if item > int(inv):
- sendo.append(item)
- api.update_status("RESTOCK \n"+title+"\n"+itemlink)
- sendd.append(item)
- optiones.append(item)
- NewItem =True
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = ("GOO \n "+itemlink)
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- sendvar = True
- price = tree12.xpath("//variants[@type='array']//price//text()")
- for item in price:
- if item < int(oldpri):
- sendo.append(item)
- api.update_status("PRICE DROP \n"+title+"\n"+itemlink)
- sendd.append(item)
- optiones.append(item)
- NewItem =True
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = ("GOO \n "+itemlink)
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- sendvar = True
- cost = item
- if sendvar == True:
- for i in sendem:
- import smtplib
- fromaddr = 'cookifyscraper@gmail.com'
- toaddrs = i
- headers = "\r\n".join([
- "subject: " + "SCRAPER "])
- msg = (time.strftime("%c")+title+"\n"+itemlink+"\n"+str(sendo))
- print msg
- content = msg
- username = 'cookifyscraper@gmail.com'
- password = 'CookifyScraper11'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddr, toaddrs, content)
- server.quit()
- tree1.clear()
- try:
- del s,getitem,sendd,tree1,strsend,inve,oldprices,oldpri,pric,pricee,variantes
- except:
- pass
- time.sleep(5)
- except Exception as E:
- print E
- global sendem
- sendem = []
- def goo():
- comm = raw_input("Command?")
- if "add link" in comm:
- sto = comm.split(" ")
- storee = sto[2]
- storelin = storee
- Thread(target=star,args=(storelin,0)).start()
- print storee+" Added!"
- goo()
- if "add email" in comm:
- em = comm.split(" ")
- sendem.append(em[2])
- print "Email - "+em[2]+" Has Been Added!"
- goo()
- goo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement