Exemplo n.º 1
0
import sys, json
sys.path.insert(0, '..')
from pyfb.pyfb import PyFb

data = json.load(open(sys.argv[1], 'r'))
image_path = sys.argv[2]

fb_client = PyFb(json.load(open('../tokens.json', 'r'))['electoralcollege'])
red_votes = sum(data['red'].values())
blue_votes = sum(data['blue'].values())
rc = data['candidates']['red']
rc = rc[:rc.index('.')]
bc = data['candidates']['blue']
bc = bc[:bc.index('.')]

winning_candidate = rc if red_votes > blue_votes else bc
losing_candidate = rc if red_votes < blue_votes else bc
winner_votes = red_votes if red_votes > blue_votes else blue_votes

pid = fb_client.create_post(message='{} has beaten {} with {} votes'.format(winning_candidate, losing_candidate, winner_votes),
	image_path=image_path)['post_id']

fb_client.comment_on_post(message='Nothing says good logging like a Facebook comment: ' + json.dumps(data),
	post_id=pid)
Exemplo n.º 2
0
import random, sys, json
sys.path.insert(0, '..')
from pyfb.pyfb import PyFb
import model, videocardgen

fb_client = PyFb(json.load(open('../tokens.json', 'r'))['scotty'])

def post(thumbnail_url, title):
	videocardgen.draw_card(thumbnail_url, title)
	fb_client.create_post(message=title, image_path='tmp-card.png')

if __name__ == '__main__':
	post(model.random_video().thumbnail, model.do_chain())
Exemplo n.º 3
0
	def __init__(self):
		self.fb_client = PyFb(json.load(open('../tokens.json', 'r'))['tetris'])
		self.db_client = sqlite3.connect('tetris.db')
Exemplo n.º 4
0
import random, sys, json
sys.path.insert(0, '..')
from pyfb.pyfb import PyFb
import imagedrawer, model

fb_client = PyFb(json.load(open('../tokens.json', 'r'))['exodia'])
deck = model.Deck(id=0)
hand = deck.draw_five()
image_path = 'out.png'
imagedrawer.draw_hand('bg.jpg', hand, out_path=image_path)
message = ''
if sorted(hand) == model.EXODIA_HAND:
    message = "THE UNSTOPPABLE EXODIA! I'VE ASSEMBLED ALL FIVE SPECIAL CARDS! ALL FIVE PIECES OF THE PUZZLE! EXODIA! OBLITERATE!!!\n"
message = message + '\n' + '\n'.join(hand)
print(message)
pid = fb_client.create_post(message=message, image_path=image_path)['post_id']
session = model.Session()
session.add(model.Post.from_fb_post_id_and_hand(pid, hand))
session.commit()
Exemplo n.º 5
0
import random, sys, json

sys.path.insert(0, '..')
from pyfb.pyfb import PyFb
import drawer, model
from angusphotos.ap import random_angus_photo_file_path

fb_client = PyFb(json.load(open('../tokens.json', 'r'))['pcbuilder'])

fb_client.create_post(message=model.pstr_pc(model.random_pc()),
                      image_path=drawer.draw_pc_mosaic())
Exemplo n.º 6
0
def get_fb_client():
    return PyFb(json.load(open('../tokens.json', 'r'))['wheresangus'])
Exemplo n.º 7
0
def iteration(db_client, fb_client):
	# get unused question count
	unused_qs = unused_questions(db_client)
	unused_question_count = 0
	if unused_qs is not None:
		unused_question_count = len(unused_qs)
	print('Unused question count:', unused_question_count)
	if unused_question_count < 400:
		print('Deciding to pull more questions')
		add_questions_to_db(db_client, 100)
		unused_qs = unused_questions(db_client)
	lp = last_post(db_client)
	la = last_answer(db_client)
	if lp is not None:
		print('Found last post id:', lp[0], 'the answer was:', la)
		fb_client.comment_on_post(lp[0], 'The answer was: ' + la)
	else:
		print('No latest post found!')

	print('Making new post!')
	chosen_question = random.choice(unused_qs)
	while chosen_question['question'].strip() == '':
		chosen_question = random.choice(unused_qs)
	print('Chose the question:', str(chosen_question))
	make_post(db_client, fb_client, chosen_question)

if __name__ == '__main__':
	db_client = sqlite3.connect('jeopardy.db')
	fb_client = PyFb(json.load(open('../tokens.json', 'r'))['jeopardy'])
	iteration(db_client, fb_client)
Exemplo n.º 8
0
import random, sys, json
sys.path.insert(0, '..')
from pyfb.pyfb import PyFb
import metallizer

fb_client = PyFb(json.load(open('../tokens.json', 'r'))['metal'])

if __name__ == '__main__':
	text, photo_path = metallizer.make_post()
	post_id = fb_client.create_post(message=text, image_path=photo_path)['post_id']

Exemplo n.º 9
0
import random, sys, json, xkcd
sys.path.insert(0, '..')
from pyfb.pyfb import PyFb

CACHE = xkcd.get_cache()


def get_post_content():
    latest_comic_num = int(xkcd.get_latest_from_cache(CACHE)['num'])
    chosen_num = random.randint(1, latest_comic_num)
    print('Picking comic, 1 <= {} <= {}'.format(chosen_num, latest_comic_num))
    comic = xkcd.get_comic(chosen_num, CACHE)
    content = 'https://xkcd.com/{}/\n#{} Title: {}\nAlt:{}'.format(
        comic['num'], comic['num'], comic['safe_title'], comic['alt'])
    if 'transcript' in comic.keys() and len(comic['transcript']) > 0:
        content += '\nTranscript:{}'.format(comic['transcript'])
    return content, xkcd.ensure_comic_image_path(comic)


if __name__ == '__main__':
    fb_client = PyFb(json.load(open('../tokens.json', 'r'))['xkcd'])
    text, image_path = get_post_content()
    fb_client.create_post(message=text, image_path=image_path)