Skip to content

Instantly share code, notes, and snippets.

@takluyver
Created April 29, 2014 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takluyver/11408873 to your computer and use it in GitHub Desktop.
Save takluyver/11408873 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# ItemStatusChecker.py
from twisted.internet import reactor
from scrapy.crawler import Crawler
from scrapy import log, signals
from site_scraper.spiders.scrape1 import MySpider
from scrapy.utils.project import get_project_settings
import wx
import time
class myWindow(wx.Frame):
def __init__(self, parent, title):
super(myWindow, self).__init__(parent, title=title,
size=(390, 350))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
panel = wx.Panel(self)
font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
font.SetPointSize(9)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
st2 = wx.StaticText(panel, label='IDs:')
st2.SetFont(font)
hbox2.Add(st2)
vbox.Add(hbox2, flag=wx.LEFT | wx.TOP, border=10)
vbox.Add((-1, 10))
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
self.tc2 = wx.TextCtrl(panel, style=wx.TE_MULTILINE)
hbox3.Add(self.tc2, proportion=1, flag=wx.EXPAND)
vbox.Add(hbox3, proportion=1, flag=wx.LEFT|wx.RIGHT|wx.EXPAND,
border=10)
vbox.Add((-1, 25))
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
cb1 = wx.CheckBox(panel, label='Export to Excel')
cb1.SetFont(font)
hbox4.Add(cb1)
vbox.Add(hbox4, flag=wx.LEFT, border=10)
vbox.Add((-1, 25))
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
self.btn1 = wx.Button(panel, label='Ok', size=(70, 30))
self.Bind(wx.EVT_BUTTON, self.OnButtonClicked, id=self.btn1.GetId())
hbox5.Add(self.btn1)
btn2 = wx.Button(panel, label='Close', size=(70, 30))
self.Bind(wx.EVT_BUTTON, self.OnExit, id=btn2.GetId())
hbox5.Add(btn2, flag=wx.LEFT|wx.BOTTOM, border=5)
vbox.Add(hbox5, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)
panel.SetSizer(vbox)
def OnExit(self, event):
self.Close()
def OnButtonClicked(self, e):
self.btn1.Hide()
savefile = open('urls.txt', 'w')
savefile.write(self.tc2.GetValue())
savefile.close()
spider = MySpider(domain='site.com')
settings = get_project_settings()
crawler = Crawler(settings)
crawler.signals.connect(reactor.stop, signal=signals.spider_closed)
crawler.configure()
crawler.crawl(spider)
crawler.start()
log.start()
reactor.run()
thedate = time.strftime("%m-%d-%y")
thefile = "Please check your Desktop for Item-Status-"+thedate+".csv"
dlg=wx.MessageDialog(self,thefile,'Status Check Complete',wx.OK)
dlg.ShowModal()
dlg.Destroy()
def main():
app = wx.App()
myWindow(None, title='Item Status Checker')
app.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment