Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import pygame
- from pygame.locals import *
- from imgurpython import ImgurClient
- from os import remove as delete
- def upload(path,album=None):
- name = path[:-4]
- client = ImgurClient('ee4818f29b62926','90246a2b4f560fe1a1c451bae7d847328680516b')
- config = {
- 'album': album,
- 'name': name,
- 'title': name,
- 'description': name
- }
- print("Uploading image... ")
- image = client.upload_from_path(path, config=config, anon=False)
- print("Done")
- return [image,path]
- def h2b(data):
- scale = 16 ## equals to hexadecimal
- num_of_bits = 128
- try:
- return bin(int(data, scale))[2:].zfill(num_of_bits)
- except:
- return ''
- def p2p(post):
- lines = []
- for i in post:
- line = str(h2b(i))
- lines.append(line)
- return lines
- def boolify(bin_lines):
- lines = []
- for line in bin_lines:
- pixels = []
- for pixel in line:
- pixels.append(bool(int(pixel)))
- lines.append(pixels)
- return lines
- def draw(pixels,exTitle="_norm"):
- pygame.init()
- size = [128,len(pixels)]
- screen = pygame.Surface(size)
- for y in range(0,len(pixels)):
- if(len(pixels[y])>0):
- for x in range(0,len(pixels[y])):
- if(pixels[y][x]):
- screen.set_at((x,y),( 255, 255, 255))
- filepath = title + exTitle + ".bmp"
- pygame.image.save(screen,filepath)
- return filepath
- user_agent = ("com.Danzi.A858BitDrawer V0.4.5 by /u/danzi218")
- r = praw.Reddit(user_agent=user_agent)
- subreddit = r.get_subreddit('A858DE45F56D9BC9')
- mask = int('A858DE45F56D9BC9'.lower()*2,16)
- bin_mask = boolify([h2b(hex(mask))])
- dp = open('done_pile.txt', 'r')
- done_pile = dp.read().split('\n')
- print(done_pile)
- dp.close()
- dp_info = []
- if(done_pile != ['']):
- for i in range(0,len(done_pile)):
- dp_info[i] = done_pile[i].split(" ")
- done_pile[i] = dp_info[i][0]
- print(done_pile)
- print(dp_info)
- new_posts = {}
- post_ids = {}
- for submission in subreddit.get_new(limit=5):
- if(submission.id not in done_pile):
- new_posts[submission.title] = submission.selftext
- post_ids[submission.title] = submission.id
- else:
- print(submission.id + " already tested:")
- for i in dp_info[done_pile.index(submission.id)]:
- print(i)
- print("---")
- for title in new_posts:
- post = new_posts[title].split(' ')
- image = p2p(post)
- norm_image = boolify(image)
- or_image = []
- xor_image = []
- for line in image:
- if(line != ''):
- line = int(line,2)
- or_image.append(h2b(hex(line | mask)))
- xor_image.append(h2b(hex(line ^ mask)))
- or_image = boolify(or_image)
- xor_image = boolify(xor_image)
- and_image = []
- for line in range(0,len(norm_image)):
- l = []
- for pixel in range(0,len(norm_image[line])):
- l.append(norm_image[line][pixel]&bin_mask[0][pixel])
- and_image.append(l)
- n = upload(draw(norm_image))
- a = upload(draw(and_image,"_and"))
- o = upload(draw(and_image,"_or"))
- x = upload(draw(and_image,"_xor"))
- images = [n,a,o,x]
- names = [',Normal:',',AND A858:',',OR A858:',',XOR A858:']
- dp = open('done_pile.txt', 'a')
- for i in range(0,len(images)):
- print(title + names[i])
- print(images[i][0]['link'])
- dp.write(post_ids[title]+ " " + title + names[i] + images[i][0]['link'])
- delete(images[i][1])
- print("---")
- dp.write("\n")
- dp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement