Permalink
Browse files

Improved border handling

  • Loading branch information...
minimaxir committed Sep 26, 2017
1 parent b2e51e6 commit 0dfb678f1955f50b54b632e57087df847ec16f05
Showing with 41 additions and 15 deletions.
  1. +16 −2 get_cardlist.py
  2. +8 −8 mtgifening.py
  3. +17 −5 utils.py
View
@@ -2,21 +2,35 @@
import csv
file_path = "/Users/maxwoolf/Downloads/AllSets.json"
MODERN_THRESH = '2003-07-29'
CURRENT_THRESH = '2014-07-28'
def encode_border(releaseDate):
if releaseDate < MODERN_THRESH:
return 'o'
elif releaseDate < CURRENT_THRESH:
return 'm'
return 'c'
with open('cards.csv', 'w', encoding='utf-8') as f:
writer = csv.writer(f)
writer.writerow(['id', 'name'])
writer.writerow(['id', 'name', 'border'])
with open(file_path, 'r') as data:
all_sets = json.load(data)
sets = all_sets.keys()
for set in sets:
border = encode_border(all_sets[set]['releaseDate'])
cards = all_sets[set]['cards']
for card in cards:
if 'multiverseid' in card:
type = card.get('type')
if (type is not None and
type == "Instant" or
type == "Sorcery" and
card['layout'] == 'normal'):
writer.writerow([card['name'], card['multiverseid']])
writer.writerow(
[card['name'], card['multiverseid'], border])
View
@@ -1,18 +1,18 @@
from utils import *
from twython import Twython
from random import randint
import random
import csv
with open('cards.csv', 'r') as f:
cards = list(csv.reader(f))
card = cards[randint(0, len(cards)-1)]
card = random.choice(cards)
create_mtg_gif(card[0], card[1])
create_mtg_gif(card[0], card[1], card[2])
twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET,
ACCESS_KEY, ACCESS_SECRET)
# twitter = Twython(CONSUMER_KEY, CONSUMER_SECRET,
# ACCESS_KEY, ACCESS_SECRET)
video = open('mtg_gif.mp4', 'rb')
response = twitter.upload_video(media=video, media_type='video/mp4')
twitter.update_status(status='', media_ids=[response['media_id']])
# video = open('mtg_gif.mp4', 'rb')
# response = twitter.upload_video(media=video, media_type='video/mp4')
# twitter.update_status(status='', media_ids=[response['media_id']])
View
@@ -31,10 +31,19 @@ def get_mtg_image(id):
return GATHERER_URL.format(id)
def create_mtg_gif(name, id):
card_upper_corner = (17, 35)
gif_width = 205 - card_upper_corner[0]
gif_height = 173 - card_upper_corner[1]
def create_mtg_gif(name, id, border):
if border == 'm': # Modern (post-8th Ed)
card_upper_corner = (19, 38)
gif_width = 202 - card_upper_corner[0]
gif_height = 171 - card_upper_corner[1]
elif border == 'c': # Current (post-Magic 2015)
card_upper_corner = (17, 35)
gif_width = 204 - card_upper_corner[0]
gif_height = 173 - card_upper_corner[1]
else: # Old (pre-8th Ed)
card_upper_corner = (25, 30)
gif_width = 196 - card_upper_corner[0]
gif_height = 168 - card_upper_corner[1]
mtg_card = Image.open(BytesIO(requests.get(get_mtg_image(id)).content))
mtg_card = ImageClip(np.asarray(mtg_card)).resize((222, 310))
@@ -45,9 +54,12 @@ def create_mtg_gif(name, id):
.set_pos(card_upper_corner)
)
giphy_gif = giphy_gif.set_duration(max(giphy_gif.duration, 2))
mtg_gif = CompositeVideoClip([mtg_card, giphy_gif])
mtg_gif = mtg_gif.set_start(0).set_duration(giphy_gif.duration)
# mtg_gif.write_gif("mtg_gif.gif")
mtg_gif.write_videofile("mtg_gif.mp4", codec='libx264', bitrate="50000000",
mtg_gif.write_videofile("mtg_gif.mp4", codec='libx264',
bitrate=str(np.power(10, 10)), verbose=False,
progress_bar=False,
audio=False, ffmpeg_params=['-pix_fmt', 'yuv420p'])

0 comments on commit 0dfb678

Please sign in to comment.