Advertisement
Guest User

A858 BitBot

a guest
Jul 12th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.50 KB | None | 0 0
  1. import praw
  2. import pygame
  3. from pygame.locals import *
  4. from imgurpython import ImgurClient
  5. from os import remove as delete
  6. def upload(path,album=None):
  7.     name = path[:-4]
  8.     client = ImgurClient('ee4818f29b62926','90246a2b4f560fe1a1c451bae7d847328680516b')
  9.     config = {
  10.     'album': album,
  11.     'name':  name,
  12.     'title': name,
  13.     'description': name
  14.     }
  15.     print("Uploading image... ")
  16.     image = client.upload_from_path(path, config=config, anon=False)
  17.     print("Done")
  18.     return [image,path]
  19. def h2b(data):
  20.     scale = 16 ## equals to hexadecimal
  21.     num_of_bits = 128
  22.     try:
  23.         return bin(int(data, scale))[2:].zfill(num_of_bits)
  24.     except:
  25.         return ''
  26. def p2p(post):
  27.     lines = []
  28.     for i in post:
  29.         line = str(h2b(i))
  30.         lines.append(line)
  31.     return lines
  32. def boolify(bin_lines):
  33.     lines = []
  34.     for line in bin_lines:
  35.         pixels = []
  36.         for pixel in line:
  37.             pixels.append(bool(int(pixel)))
  38.         lines.append(pixels)
  39.     return lines
  40. def draw(pixels,exTitle="_norm"):
  41.     pygame.init()
  42.     size = [128,len(pixels)]
  43.     screen = pygame.Surface(size)
  44.     for y in range(0,len(pixels)):
  45.         if(len(pixels[y])>0):
  46.             for x in range(0,len(pixels[y])):
  47.                 if(pixels[y][x]):
  48.                     screen.set_at((x,y),( 255, 255, 255))
  49.     filepath = title + exTitle + ".bmp"
  50.     pygame.image.save(screen,filepath)
  51.     return filepath
  52.  
  53. user_agent = ("com.Danzi.A858BitDrawer V0.4.5 by /u/danzi218")
  54. r = praw.Reddit(user_agent=user_agent)
  55. subreddit = r.get_subreddit('A858DE45F56D9BC9')
  56. mask = int('A858DE45F56D9BC9'.lower()*2,16)
  57. bin_mask = boolify([h2b(hex(mask))])
  58. dp = open('done_pile.txt', 'r')
  59. done_pile = dp.read().split('\n')
  60. print(done_pile)
  61. dp.close()
  62. dp_info = []
  63. if(done_pile != ['']):
  64.     for i in range(0,len(done_pile)):
  65.         dp_info[i] = done_pile[i].split(" ")
  66.         done_pile[i] = dp_info[i][0]
  67. print(done_pile)
  68. print(dp_info)
  69. new_posts = {}
  70. post_ids = {}
  71. for submission in subreddit.get_new(limit=5):
  72.     if(submission.id not in done_pile):
  73.         new_posts[submission.title] = submission.selftext
  74.         post_ids[submission.title] = submission.id
  75.     else:
  76.         print(submission.id + " already tested:")
  77.         for i in dp_info[done_pile.index(submission.id)]:
  78.             print(i)
  79.         print("---")
  80. for title in new_posts:
  81.     post = new_posts[title].split(' ')
  82.     image = p2p(post)
  83.     norm_image = boolify(image)
  84.     or_image = []
  85.     xor_image = []
  86.     for line in image:
  87.         if(line != ''):
  88.             line = int(line,2)
  89.             or_image.append(h2b(hex(line | mask)))
  90.             xor_image.append(h2b(hex(line ^ mask)))
  91.     or_image = boolify(or_image)    
  92.     xor_image = boolify(xor_image)
  93.     and_image = []
  94.     for line in range(0,len(norm_image)):
  95.         l = []
  96.         for pixel in range(0,len(norm_image[line])):
  97.             l.append(norm_image[line][pixel]&bin_mask[0][pixel])
  98.         and_image.append(l)
  99.     n = upload(draw(norm_image))
  100.     a = upload(draw(and_image,"_and"))
  101.     o = upload(draw(and_image,"_or"))
  102.     x = upload(draw(and_image,"_xor"))
  103.     images = [n,a,o,x]
  104.     names = [',Normal:',',AND A858:',',OR A858:',',XOR A858:']
  105.     dp = open('done_pile.txt', 'a')
  106.     for i in range(0,len(images)):
  107.         print(title + names[i])
  108.         print(images[i][0]['link'])
  109.         dp.write(post_ids[title]+ " " + title + names[i] + images[i][0]['link'])
  110.         delete(images[i][1])
  111.         print("---")
  112.     dp.write("\n")
  113.     dp.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement