-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpfp.py
More file actions
34 lines (26 loc) · 862 Bytes
/
pfp.py
File metadata and controls
34 lines (26 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import scratchattach as sa
from PIL import Image
from io import BytesIO
from dotenv import load_dotenv
import os, requests, warnings
warnings.filterwarnings('ignore', category=sa.LoginDataWarning)
load_dotenv()
PASSWORD = os.getenv("SCRATCH_PASSWORD")
session = sa.login("the_cool_scratch_guy", PASSWORD)
user = session.connect_user("the_cool_scratch_guy")
pfp_url = user.icon_url
# Download the image
response = requests.get(pfp_url)
response.raise_for_status() # good practice
# open it with Pillow and get pixels
img = Image.open(BytesIO(response.content))
pixels = img.load()
big_string = ""
width, height = img.size
for y in range(height):
for x in range(width):
r, g, b = pixels[x, y]
color_int = r*65536 + g*256 + b
color_string = str(color_int).zfill(8)
big_string += color_string
big_string += str(width)