Wxpython auto refresh every five minutes?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Souleiman
    New Member
    • Jul 2010
    • 1

    Wxpython auto refresh every five minutes?

    Hello everybody,
    i have a script that goes to one website of mine, checks if there is a code available(using urllib2), then, by using wxpython prints the code availability status.

    Is there any way i can make my program research for a code every five minutes, then update the text printed on the screen? this program intended to be run in the background.

    Also, if it finds a code, if i could make it to ring that would be great.

    If it'll help, here is my program's source code.
    Code:
    #SwagNotifier v1.0 By redhat for activeSwagCodes.
    import wx, datetime, urllib2
    #Fetching the swagcode infos
    swagcode = 1
    req = urllib2.Request('http://activeswagcodes.com/swagfeed/status.php')
    handle = urllib2.urlopen(req)
    raw_info = handle.read()
    codeinfo = raw_info.split() # codeinfo is an array which has code at 0 value at 1 and expiry at 2
    if codeinfo[0]=="no":
        swagcode=0
    #Window Drawing begins here on:
    class SwagNotifier(wx.Frame):
        def __init__(self):
            wx.Frame.__init__(self, None, -1, 'SwagNotifier 1.0 By ActiveSwagCodes.com', size=(436, 240))
            try:
                image_file = 'SwidgetBG.jpg'
                bmp1 = wx.Image(image_file, wx.BITMAP_TYPE_ANY).ConvertToBitmap()
                panel = wx.StaticBitmap(self, -1, bmp1, (0, 0))
                # show some image details in the title
            except IOError:
                raise SystemExit
            # printing text from here on
            if swagcode==1:
                str = "Swagcode available!"
                textcolor = 'blue'
            else:
                str = "No Swagcode :("
                textcolor = 'red'
        
            text = wx.StaticText(panel, -1, str, (115, 45)) 
            font = wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD)
            text.SetBackgroundColour('white')
            text.SetForegroundColour(textcolor)
            text.SetFont(font)
            if swagcode==1:
                textcolor = 'black'
                text2 = "SwagCode: %s" % "Go To ActiveSwag"
                text2_ac = wx.StaticText(panel, -1, text2, (110, 90))
                text2_ac.SetBackgroundColour('white')
                text2_ac.SetForegroundColour(textcolor)
                code_font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.BOLD)
                text2_ac.SetFont(code_font)
                text5 = "Codes.com to get it!"
                text5_ac = wx.StaticText(panel, -1, text5, (140, 110))
                text5_ac.SetBackgroundColour('white')
                text5_ac.SetForegroundColour(textcolor)
                text5_ac.SetFont(code_font)
                text3 = "Value: %s" % codeinfo[1]
                text3_ac = wx.StaticText(panel, -1, text3, (110, 130))
                text3_ac.SetBackgroundColour('white')
                text3_ac.SetForegroundColour(textcolor)
                text3_ac.SetFont(code_font)
                text4 = "Expire Time: %s" % codeinfo[2]
                text4_ac = wx.StaticText(panel, -1, text4, (110, 150))
                text4_ac.SetBackgroundColour('white')
                text4_ac.SetForegroundColour(textcolor)
                text4_ac.SetFont(code_font)
    app = wx.PySimpleApp()
    frame = SwagNotifier()
    frame.Show()
    app.MainLoop()
    Thanks for trying to help me, I have some people waiting on me for this project and I'd like to complete it as soon as possible!

    -souleiman
Working...