Skip to content

Instantly share code, notes, and snippets.

@cunningham
Created May 22, 2015 17:32
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 cunningham/3f3ae2e4ef5a119662cf to your computer and use it in GitHub Desktop.
Save cunningham/3f3ae2e4ef5a119662cf to your computer and use it in GitHub Desktop.
Towerfall replay poster
from hypchat import HypChat
import pyimgur
import glob
import os
#Info
hc_token = 'HIPCHAT_TOKEN'
replay_dir = '/PATH/TO/REPLAYS/'
posted_dir = '/PATH/TO/POSTED/FILES/'
imgur_client_id = 'IMGUR_CLIENT_ID'
room_to_post_to = 'TowerFall'
#Setup connections
h = HypChat(hc_token)
im = pyimgur.Imgur(imgur_client_id)
files_to_post = glob.glob('{0}/*.gif'.format(replay_dir))
room = h.get_room(room_to_post_to)
#Iterate through files, uploading to imgur and posting link to Hipchat.
for f in files_to_post:
num_posted_files = len(glob.glob('{0}/*.gif'.format(posted_dir)))
file_name = 'replay{0}.gif'.format(str(num_posted_files + 1))
os.rename(f, '{0}/posted/{1}'.format(replay_dir,file_name))
uploaded_img = im.upload_image('{0}/posted/{1}'.format(replay_dir,file_name),title=file_name)
room.message('{0}: {1}'.format(file_name,uploaded_img.link),format='text')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment