diff --git a/Ubuntu-B.ttf b/Ubuntu-B.ttf new file mode 100644 index 0000000..b173da2 Binary files /dev/null and b/Ubuntu-B.ttf differ diff --git a/Ubuntu-R.ttf b/Ubuntu-R.ttf new file mode 100644 index 0000000..d748728 Binary files /dev/null and b/Ubuntu-R.ttf differ diff --git a/cmc.py b/cmc.py index a230f8f..a947ed7 100644 --- a/cmc.py +++ b/cmc.py @@ -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 diff --git a/img/coins/augur.png b/img/coins/augur.png index 97fbcf4..134191a 100644 Binary files a/img/coins/augur.png and b/img/coins/augur.png differ diff --git a/img/coins/bitcoin.png b/img/coins/bitcoin.png index d2da9cd..a4d7221 100644 Binary files a/img/coins/bitcoin.png and b/img/coins/bitcoin.png differ diff --git a/img/coins/dash.png b/img/coins/dash.png index f94c7e8..0c5aaf5 100644 Binary files a/img/coins/dash.png and b/img/coins/dash.png differ diff --git a/img/coins/ethereum-classic.png b/img/coins/ethereum-classic.png index 4087aa4..293c73f 100644 Binary files a/img/coins/ethereum-classic.png and b/img/coins/ethereum-classic.png differ diff --git a/img/coins/ethereum.png b/img/coins/ethereum.png index 0b2f4c3..c4838e0 100644 Binary files a/img/coins/ethereum.png and b/img/coins/ethereum.png differ diff --git a/img/coins/golem-network-tokens.png b/img/coins/golem-network-tokens.png index e447926..12f36d3 100644 Binary files a/img/coins/golem-network-tokens.png and b/img/coins/golem-network-tokens.png differ diff --git a/img/coins/litecoin.png b/img/coins/litecoin.png index 767277b..d71a198 100644 Binary files a/img/coins/litecoin.png and b/img/coins/litecoin.png differ diff --git a/img/coins/maidsafecoin.png b/img/coins/maidsafecoin.png index c8c1557..9a655bb 100644 Binary files a/img/coins/maidsafecoin.png and b/img/coins/maidsafecoin.png differ diff --git a/img/coins/monero.png b/img/coins/monero.png index f6ddae3..3510454 100644 Binary files a/img/coins/monero.png and b/img/coins/monero.png differ diff --git a/img/coins/nem.png b/img/coins/nem.png index 8319039..1e8b1e0 100644 Binary files a/img/coins/nem.png and b/img/coins/nem.png differ diff --git a/img/coins/ripple.png b/img/coins/ripple.png index 555d489..942bc8e 100644 Binary files a/img/coins/ripple.png and b/img/coins/ripple.png differ diff --git a/img/coins/tether.png b/img/coins/tether.png index ea435d6..aeff62c 100644 Binary files a/img/coins/tether.png and b/img/coins/tether.png differ diff --git a/img/coins/unknown.png b/img/coins/unknown.png new file mode 100644 index 0000000..df0c225 Binary files /dev/null and b/img/coins/unknown.png differ diff --git a/img/coins/zcash.png b/img/coins/zcash.png index f371937..64b7556 100644 Binary files a/img/coins/zcash.png and b/img/coins/zcash.png differ diff --git a/img/coins_backup/augur.png b/img/coins_backup/augur.png new file mode 100644 index 0000000..97fbcf4 Binary files /dev/null and b/img/coins_backup/augur.png differ diff --git a/img/coins_backup/bitcoin.png b/img/coins_backup/bitcoin.png new file mode 100644 index 0000000..d2da9cd Binary files /dev/null and b/img/coins_backup/bitcoin.png differ diff --git a/img/coins_backup/dash.png b/img/coins_backup/dash.png new file mode 100644 index 0000000..f94c7e8 Binary files /dev/null and b/img/coins_backup/dash.png differ diff --git a/img/coins_backup/ethereum-classic.png b/img/coins_backup/ethereum-classic.png new file mode 100644 index 0000000..4087aa4 Binary files /dev/null and b/img/coins_backup/ethereum-classic.png differ diff --git a/img/coins_backup/ethereum.png b/img/coins_backup/ethereum.png new file mode 100644 index 0000000..0b2f4c3 Binary files /dev/null and b/img/coins_backup/ethereum.png differ diff --git a/img/coins_backup/golem-network-tokens.png b/img/coins_backup/golem-network-tokens.png new file mode 100644 index 0000000..e447926 Binary files /dev/null and b/img/coins_backup/golem-network-tokens.png differ diff --git a/img/coins_backup/litecoin.png b/img/coins_backup/litecoin.png new file mode 100644 index 0000000..767277b Binary files /dev/null and b/img/coins_backup/litecoin.png differ diff --git a/img/coins_backup/maidsafecoin.png b/img/coins_backup/maidsafecoin.png new file mode 100644 index 0000000..c8c1557 Binary files /dev/null and b/img/coins_backup/maidsafecoin.png differ diff --git a/img/coins_backup/monero.png b/img/coins_backup/monero.png new file mode 100644 index 0000000..f6ddae3 Binary files /dev/null and b/img/coins_backup/monero.png differ diff --git a/img/coins_backup/nem.png b/img/coins_backup/nem.png new file mode 100644 index 0000000..8319039 Binary files /dev/null and b/img/coins_backup/nem.png differ diff --git a/img/coins_backup/ripple.png b/img/coins_backup/ripple.png new file mode 100644 index 0000000..555d489 Binary files /dev/null and b/img/coins_backup/ripple.png differ diff --git a/img/coins_backup/tether.png b/img/coins_backup/tether.png new file mode 100644 index 0000000..ea435d6 Binary files /dev/null and b/img/coins_backup/tether.png differ diff --git a/img/coins_backup/unknown.png b/img/coins_backup/unknown.png new file mode 100644 index 0000000..2ab6aaa Binary files /dev/null and b/img/coins_backup/unknown.png differ diff --git a/img/coins_backup/zcash.png b/img/coins_backup/zcash.png new file mode 100644 index 0000000..f371937 Binary files /dev/null and b/img/coins_backup/zcash.png differ diff --git a/img/cryptocurrencies-bg-fade1.jpg b/img/cryptocurrencies-bg-fade1.jpg new file mode 100644 index 0000000..37c874a Binary files /dev/null and b/img/cryptocurrencies-bg-fade1.jpg differ diff --git a/img/reddit.png b/img/reddit.png new file mode 100644 index 0000000..f15108c Binary files /dev/null and b/img/reddit.png differ diff --git a/img/temp/augur.png b/img/temp/augur.png new file mode 100644 index 0000000..0685fcf Binary files /dev/null and b/img/temp/augur.png differ diff --git a/img/temp/bitcoin.png b/img/temp/bitcoin.png new file mode 100644 index 0000000..bf969b8 Binary files /dev/null and b/img/temp/bitcoin.png differ diff --git a/img/temp/dash.png b/img/temp/dash.png new file mode 100644 index 0000000..30eaf46 Binary files /dev/null and b/img/temp/dash.png differ diff --git a/img/temp/ethereum-classic.png b/img/temp/ethereum-classic.png new file mode 100644 index 0000000..2aafe94 Binary files /dev/null and b/img/temp/ethereum-classic.png differ diff --git a/img/temp/ethereum.png b/img/temp/ethereum.png new file mode 100644 index 0000000..65424a7 Binary files /dev/null and b/img/temp/ethereum.png differ diff --git a/img/temp/leader.png b/img/temp/leader.png new file mode 100644 index 0000000..9f0db17 Binary files /dev/null and b/img/temp/leader.png differ diff --git a/img/temp/litecoin.png b/img/temp/litecoin.png new file mode 100644 index 0000000..a3c4ed4 Binary files /dev/null and b/img/temp/litecoin.png differ diff --git a/img/temp/maidsafecoin.png b/img/temp/maidsafecoin.png new file mode 100644 index 0000000..e0d5e03 Binary files /dev/null and b/img/temp/maidsafecoin.png differ diff --git a/img/temp/monero.png b/img/temp/monero.png new file mode 100644 index 0000000..eb4edc5 Binary files /dev/null and b/img/temp/monero.png differ diff --git a/img/temp/nem.png b/img/temp/nem.png new file mode 100644 index 0000000..b9427bf Binary files /dev/null and b/img/temp/nem.png differ diff --git a/img/temp/ripple.png b/img/temp/ripple.png new file mode 100644 index 0000000..1c82012 Binary files /dev/null and b/img/temp/ripple.png differ diff --git a/img/temp/ticker.png b/img/temp/ticker.png new file mode 100644 index 0000000..8ed889f Binary files /dev/null and b/img/temp/ticker.png differ diff --git a/img/watermark-background-3.png b/img/watermark-background-3.png new file mode 100644 index 0000000..aca9661 Binary files /dev/null and b/img/watermark-background-3.png differ diff --git a/imggen.py b/imggen.py new file mode 100644 index 0000000..cf6c70d --- /dev/null +++ b/imggen.py @@ -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 diff --git a/main.py b/main.py index 2b174cc..6ce5c27 100644 --- a/main.py +++ b/main.py @@ -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) diff --git a/reddit.py b/reddit.py deleted file mode 100644 index 446178f..0000000 --- a/reddit.py +++ /dev/null @@ -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) - diff --git a/scrollingheader.css b/scrollingheader.css new file mode 100644 index 0000000..18654f4 --- /dev/null +++ b/scrollingheader.css @@ -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; } +} + diff --git a/testpil.py b/testpil.py new file mode 100644 index 0000000..b5a77c7 --- /dev/null +++ b/testpil.py @@ -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))