First working version.

This commit is contained in:
jw
2017-04-25 20:20:24 -07:00
parent 1804bb542a
commit 52656e2aa5
51 changed files with 178 additions and 38 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3 -3
View File
@@ -13,6 +13,6 @@ def getcmc():
print("Failed to get CMC via API")
with open('cachedCMC.txt', 'r') as f:
j = f.read().json()
for i in j:
ticker_string += "|{}|${}|B{}".format(i['symbol'], i['price_usd'], i['price_btc'])
return ticker_string
# for i in j:
# print(i)
return j
Binary file not shown.

Before

Width:  |  Height:  |  Size: 516 B

After

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 982 B

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 518 B

After

Width:  |  Height:  |  Size: 626 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 670 B

After

Width:  |  Height:  |  Size: 782 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 304 B

After

Width:  |  Height:  |  Size: 360 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 439 B

After

Width:  |  Height:  |  Size: 611 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 B

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 837 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 802 B

After

Width:  |  Height:  |  Size: 867 B

BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 875 B

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 907 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 404 B

After

Width:  |  Height:  |  Size: 555 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 788 B

After

Width:  |  Height:  |  Size: 948 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 982 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 670 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 837 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 875 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

+77
View File
@@ -0,0 +1,77 @@
from PIL import Image, ImageChops, ImageFont, ImageDraw
import cmc
import os
def trim(im):
bg = Image.new(im.mode, im.size, im.getpixel((0,0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
print(bbox)
if bbox:
# return im.crop(bbox)
return im.crop((bbox[0], 0, bbox[2], 18))
def imggen():
cmcdata = cmc.getcmc()
# font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/arial.ttf",16)
spacing = 60
logosize = 16
bufferspace = 60
font = ImageFont.truetype("Ubuntu-B.ttf",16)
coinimglist = []
for root, dirs, files in os.walk("img/coins/"):
for file in files:
if file.endswith(".png"):
coinimglist.append(os.path.join(root, file))
# print(coinimglist)
widthlist = []
toptenlist = []
leaderimg = Image.new("RGBA", (400,18), (200,240,255,255))
draw = ImageDraw.Draw(leaderimg)
draw.text((0,0), "Rank Coin Marketcap Price(USD)", (0,0,0), font=font)
leaderimg = trim(leaderimg)
widthlist.append(leaderimg.size[0])
leaderimg.save("img/temp/leader.png")
for idx,val in enumerate(cmcdata):
if idx == 0:
img = Image.new("RGBA", (400,18), (200,255,200,255))
else:
img = Image.new("RGBA", (400,18), (255,255,255,255))
draw = ImageDraw.Draw(img)
text = "#{} {} ${:,.0f} ${:.2f}".format(val['rank'], val['symbol'], float(val['market_cap_usd']), float(val['price_usd']))
draw.text((0,0), text, (0,0,0), font=font)
img = trim(img)
img.save("img/temp/{}.png".format(val['id']))
widthlist.append(img.size[0])
toptenlist.append(val['id'])
x_offset = 0
tickerimg = Image.new("RGBA", (sum(widthlist)+10*(spacing+logosize)+bufferspace,18), (255,255,255,255))
tickerimg.paste(leaderimg, (x_offset, 0))
x_offset += widthlist[0]
for idx,val in enumerate(toptenlist):
coinimg = Image.open("img/coins/unknown.png")
for i in coinimglist:
# print(cmcdata[idx]['id'], coinimglist[idx])
if cmcdata[idx]['id'] in i:
coinimg = Image.open("img/coins/{0}.png".format(cmcdata[idx]['id']))
textimg = Image.open("img/temp/{0}.png".format(cmcdata[idx]['id']))
# arr = np.array(coinimg)
# print(arr)
# coinimgbg = Image.new("RGBA", (16,16), (255,255,255,255))
# print("Size of coinimg is {}, and size of coinimgbg is {}".format(coinimg.size, coinimgbg.size))
# print("Mode of coinimg is {}, and mode of coinimgbg is {}".format(coinimg.mode, coinimgbg.mode))
# coinimg = Image.alpha_composite(coinimgbg, coinimg)
tickerimg.paste(coinimg, (x_offset+spacing, 1))
tickerimg.paste(textimg, (x_offset+spacing+logosize, 0))
x_offset += widthlist[idx+1] + 76
tickerimg.save("img/temp/ticker.png")
print("Ticker image size = {}".format(tickerimg.size))
return tickerimg
+12 -26
View File
@@ -1,30 +1,16 @@
import reddit
import cmc
import imggen
import praw
from userpw import *
prawer = reddit.prawer()
prawer.r.login(reddit.username, reddit.password)
tickerimg = imggen.imggen()
sub = prawer.r.get_subreddit('xdn')
ss = sub.get_stylesheet()
reddit = praw.Reddit(client_id=client_id, client_secret=client_secret,
username=username, password=password,
user_agent=user_agent)
ticker_text = cmc.getcmc()
ss_text = """
#header {
background-repeat: repeat;
-webkit-animation: banner 300s infinite linear;
animation: banner 300s infinite linear;
}
@-webkit-keyframes banner {
from { background-position: 0 0px; }
to { background-position: -5402px 500px; }
}
@keyframes banner {
from { background-position: 0 0px; }
to { background-position: -5402px 0px; }
}
"""
sub.set_stylesheet(ss_text)
print(reddit.user.me())
sub = reddit.subreddit('ccticker')
print(sub.title)
ss = sub.stylesheet()
sub.stylesheet.upload("ticker", "img/temp/ticker.png")
sub.stylesheet.update(stylesheettext)
-9
View File
@@ -1,9 +0,0 @@
import praw
from userpw import *
class prawer:
def __init__(self):
self.r = praw.Reddit(client_id=client_id, client_secret=client_secret,
username=username, password=password,
user_agent=user_agent)
+16
View File
@@ -0,0 +1,16 @@
#header {
background-repeat: repeat;
-webkit-animation: banner 300s infinite linear;
animation: banner 300s infinite linear;
}
@-webkit-keyframes banner {
from { background-position: 0 0px; }
to { background-position: -5402px 500px; }
}
@keyframes banner {
from { background-position: 0 0px; }
to { background-position: -5402px 0px; }
}
+70
View File
@@ -0,0 +1,70 @@
from PIL import Image, ImageChops, ImageFont, ImageDraw
import cmc
import os
def trim(im):
bg = Image.new(im.mode, im.size, im.getpixel((0,0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)
bbox = diff.getbbox()
if bbox:
return im.crop(bbox)
def imggen():
cmcdata = cmc.getcmc()
# font = ImageFont.truetype("/usr/share/fonts/truetype/msttcorefonts/arial.ttf",16)
font = ImageFont.truetype("Ubuntu-B.ttf",16)
coinimglist = []
for root, dirs, files in os.walk("img/coins/"):
for file in files:
if file.endswith(".png"):
coinimglist.append(os.path.join(root, file))
# print(coinimglist)
widthlist = []
toptenlist = []
leaderimg = Image.new("RGBA", (400,16), (200,240,255,255))
draw = ImageDraw.Draw(leaderimg)
draw.text((0,0), "Rank | Coin | Market Cap | Price (USD)", (0,0,0), font=font)
leaderimg = trim(leaderimg)
widthlist.append(leaderimg.size[0])
leaderimg.save("img/temp/leader.png")
for idx,val in enumerate(cmcdata):
if idx == 0:
img = Image.new("RGBA", (400,16), (200,255,200,255))
else:
img = Image.new("RGBA", (400,16), (225,225,225,255))
draw = ImageDraw.Draw(img)
text = "#{} | {} | ${:,.0f} | ${:.2f}".format(val['rank'], val['symbol'], float(val['market_cap_usd']), float(val['price_usd']))
draw.text((0,0), text, (0,0,0), font=font)
img = trim(img)
img.save("img/temp/{}.png".format(val['id']))
widthlist.append(img.size[0])
toptenlist.append(val['id'])
x_offset = 0
tickerimg = Image.new("RGBA", (sum(widthlist)+300,16), (255,255,255,255))
tickerimg.paste(leaderimg, (x_offset, 0))
x_offset += widthlist[0]
for idx,val in enumerate(toptenlist):
coinimg = Image.open("img/coins/unknown.png")
for i in coinimglist:
# print(cmcdata[idx]['id'], coinimglist[idx])
if cmcdata[idx]['id'] in i:
coinimg = Image.open("img/coins/{0}.png".format(cmcdata[idx]['id']))
textimg = Image.open("img/temp/{0}.png".format(cmcdata[idx]['id']))
# arr = np.array(coinimg)
# print(arr)
# coinimgbg = Image.new("RGBA", (16,16), (255,255,255,255))
# print("Size of coinimg is {}, and size of coinimgbg is {}".format(coinimg.size, coinimgbg.size))
# print("Mode of coinimg is {}, and mode of coinimgbg is {}".format(coinimg.mode, coinimgbg.mode))
# coinimg = Image.alpha_composite(coinimgbg, coinimg)
tickerimg.paste(coinimg, (x_offset+10, 0))
tickerimg.paste(textimg, (x_offset+26, 0))
x_offset += widthlist[idx+1] + 26
tickerimg.save("img/temp/ticker.png")
print("Ticker image size = {}".format(tickerimg.size))