Skip to content

Instantly share code, notes, and snippets.

@33mhz
Created March 17, 2017 00:55
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 33mhz/69ca1a6a01093754aeb59f6bcb4236b5 to your computer and use it in GitHub Desktop.
Save 33mhz/69ca1a6a01093754aeb59f6bcb4236b5 to your computer and use it in GitHub Desktop.
# Author: @33MHz
# 2017-03-04 hackday
# Polls, printing to USB receipt printer
from pnutpy import api
import subprocess
from shlex import quote
api.add_authorization_token('TOKEN HERE')
# get since_id from file
try:
f = open("FOLDER LOCATION/since_id","r")
except:
f = open("FOLDER LOCATION/since_id","w")
since_id = f.read()
f.close()
if not since_id or since_id == '':
since_id = 1
# get tags
posts = api.posts_with_hashtag('pnutprinter',since_id=since_id,include_deleted=0)
# save since_id
f = open("FOLDER LOCATION/since_id","w")
try:
posts[0][0].id
except:
f.write(since_id)
else:
f.write(str(posts[0][0].id))
f.close()
# repost them
for post in reversed(posts[0]):
cmd = "echo "+ str(post.id) +" @"+post.user.username+": "+ quote(post.content.text) +" | lpr -P receipt"
try:
# repost
api.repost_post(post.id)
# print
subprocess.check_output(cmd, shell=True)
except:
print('error reposting or printing')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment