Advertisement
paster442

assets.scratch.mt.edu image uploader

Sep 23rd, 2021 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import hashlib
  2. import pyperclip
  3. import requests
  4. from termcolor import colored
  5. from tkinter import filedialog, Tk
  6.  
  7. CSRF_TOKEN = "dQw4w9WgXcQ"
  8. SESSION_ID = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
  9.  
  10.  
  11. def get_image():
  12.     root = Tk()
  13.     root.withdraw()
  14.     image = filedialog.askopenfilenames(title = "Upload")
  15.     return image[0]
  16.  
  17.  
  18. image = get_image()
  19. file_data = open(image, "rb")
  20.  
  21.  
  22. def md5(fname):
  23.     hash_md5 = hashlib.md5()
  24.     with open(fname, "rb") as f:
  25.         for chunk in iter(lambda: f.read(4096), b""):
  26.             hash_md5.update(chunk)
  27.     return hash_md5.hexdigest()
  28.  
  29.  
  30. def get_extension(file):
  31.     i = None
  32.     for i in range(0, len(image) + 1):
  33.         if image[i] == ".":
  34.             break
  35.     return image[i:]
  36.  
  37.  
  38. extension = get_extension(image)
  39. hash = md5(image)
  40.  
  41. requests.post(
  42.     f"https://assets.scratch.mit.edu/{hash}{extension}",
  43.     data = file_data,
  44.     cookies = {
  45.         "scratchcsrftoken": CSRF_TOKEN,
  46.         "scratchsessionsid": SESSION_ID
  47.     }
  48. )
  49.  
  50. link = f"https://assets.scratch.mit.edu/get_image/.%2E/{hash}{extension}"
  51. link_with_bbcode = f"[img]https://assets.scratch.mit.edu/get_image/.%2E/{hash}{extension}[/img]"
  52.  
  53. print(colored(link, "green") + "\n" + colored(link_with_bbcode, "green"))
  54. pyperclip.copy(link)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement