Skip to content

Instantly share code, notes, and snippets.

@stopfaner
Last active August 29, 2015 14:12
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 stopfaner/5e3c1aa54887fdafc14d to your computer and use it in GitHub Desktop.
Save stopfaner/5e3c1aa54887fdafc14d to your computer and use it in GitHub Desktop.
Ready daemon to monitor new queries on Parse.com
import cups
import time
import json,httplib
import random
import qrcode
from xhtml2pdf import pisa
notes = 7
array = {}
mSeconds = 2
def queries():
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('GET', '/1/classes/TestPay', '', {
"X-Parse-Application-Id": "GuhHHtOKF2Sy4CEJ7sP7HZnZiW28DgDnPs4C3r00",
"X-Parse-REST-API-Key": "wboJ1C6gcqH2DYnUQmfw4PU3X7zoS7bgyfvBQACZ"
})
result = json.loads(connection.getresponse().read())
global array
array = result
return len(result['results'])
def checkNumber():
number = ""
for i in range(10):
number += str(random.randint(0,9))
return number
def main():
while True:
print queries()
if queries() > notes:
global notes
notes+=1
filename = "/home/stopfan/Developing/python/print.pdf"
xhtml = "<h1>Easy2Pay</h1>\n"
xhtml += "<h2>Check number: "+checkNumber()+"</h2>\n"
xhtml += "<h2>Date: "+array['results'][notes-1]['createdAt']+"</h2>"
xhtml += "<h2>Login: "+array['results'][notes-1]['Login']+"</h2>"
xhtml += "<h2>Password: "+array['results'][notes-1]['Password']+"</h2>"
xhtml += "<h2>Email: "+array['results'][notes-1]['Email']+"</h2>"
xhtml += "<h2>Count: "+str(array['results'][notes-1]['Pay'])+"</h2>"
xhtml += "<h2>http://www.easy2pay.cou.ua</h2>"
qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=5,
border=4,
)
qr.add_data('http://www.easy2pay.cou.ua')
qr.make(fit=True)
img = qr.make_image()
img.save("/home/stopfan/Developing/python/qr.jpg")
xhtml += "<p><img src='/home/stopfan/Developing/python/qr.jpg'/></p>"
pdf = pisa.CreatePDF(xhtml, file(filename, "w"))
if not pdf.err:
pdf.dest.close()
conn = cups.Connection()
printers = conn.getPrinters()
for printer in printers:
print printer, printers[printer]["device-uri"]
printer_name = printers.keys()[0]
conn.printFile(printer_name, filename, "Python_print",{})
else:
print "Unable to create file"
time.sleep(mSeconds)
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment