timeNow = date.today() dateNow = timeNow.strftime("%Y-%m-%d") yearNow = timeNow.strftime("%Y") monthNow = timeNow.strftime("%m") calendarAddress = urljoin(drygUri, drygPath) if verbose: print "\n*** Todays date: %s" % dateNow print print "*** Calendar source: %s" % calendarAddress # getting calendars for twelve months # check if connected to internet connected = internetAccess(testAddress, verbose) if connected: # connect to database cnx = db_connect(verbose) # create cursor cursor = db_create_cursor(cnx, verbose) for i in range(0, months, 1): lookupDate = timeNow + relativedelta(months=i) lookupYear = lookupDate.strftime("%Y") lookupMonth = lookupDate.strftime("%m") calendarPath = "%s/%s/%s" % (calendarAddress, lookupYear, lookupMonth)
def button1Pressed(): # find days in database line_1 = "No data" # connect to database cnx = db_connect(verbose) # create cursor cursor = db_create_cursor(cnx, verbose) query = "SELECT date, DATEDIFF(date,CURDATE()) FROM days ORDER BY date DESC LIMIT 1" result, rowCount = db_query(cursor, query, verbose) # run query try: result, rowCount = db_query(cursor, query, verbose) # run query except MySQLdb.Error as e: print "\n<br>Error: Could not get number of days \n<br>%s" % e print "\n<br>SQL: %s" % query else: if rowCount: if verbose: print "\n*** Got a result" for row in result: lastDate = row[0] daysToEnd = row[1] if verbose: print " Days in db: %s" % daysToEnd print " Days in db: %s" % lastDate line_1 = "%s, %s" % (daysToEnd, lastDate.strftime("%Y-%m-%d")) # find this devices ip address interfaceIPs = [] line_2 = "Not connected" if verbose: print "\n*** Finding interfaces..." interfaces = ni.interfaces() if verbose: print " Found %s interfaces" % len(interfaces) print "\n*** Looking up ip addresses..." i = 0 for interface in interfaces: try: ip = ni.ifaddresses(interface)[ni.AF_INET][0]['addr'] except: ip = "NA" interfaceIPs.append({"interface%s" % i: interface, "ip%s" % i: ip}) i += 1 i = 0 for interfaceIP in interfaceIPs: if verbose: print " Interface: %s" % interfaceIP['interface%s' % i] print " IP: %s" % interfaceIP['ip%s' % i] if (not interfaceIP['ip%s' % i].startswith('127') and not interfaceIP['ip%s' % i].startswith('169') and not interfaceIP['ip%s' % i] == "NA"): line_2 = interfaceIP['ip%s' % i] if verbose: print "*** This is the one we will display" if verbose: print i += 1 if internetAccess(testAddress, verbose): line_2 = "*%s" % line_2 else: line_2 = "-%s" % line_2 return line_1, line_2 # close cursor db_close_cursor(cnx, cursor, verbose) # close db db_disconnect(cnx, verbose)