repl.it
@Scoder12/

repl.it language icon download

Python

No description

fork
loading
Files
  • main.py
  • apl.png
  • babel.png
  • bash.png
  • bloop.png
  • brainfuck.png
  • c.png
  • clojure.png
  • coffeescript.png
  • cpp.png
  • cpp11.png
  • crystal.png
  • csharp.png
  • dart.png
  • django.png
  • elisp.png
  • elixir.png
  • emoticon.png
  • enzyme.png
  • erlang.png
  • express.png
  • flow.png
  • forth.png
  • fsharp.png
  • gatsbyjs.png
  • gatsbyjsv2.png
  • go_beta.png
  • go.png
  • haskell.png
  • html.png
  • java_swing.png
  • java.png
  • java10.png
  • javascript.png
  • jest.png
  • julia.png
  • kotlin.png
  • lang_icons.json
  • langs.json
  • lolcode.png
  • love2d.png
  • lua.png
  • nextjs.png
  • nim.png
  • nodejs_beta.png
  • nodejs_prybar.png
  • nodejs.png
  • ocaml.png
  • perl6.png
  • php_cli.png
  • php_server.png
  • php.png
  • php7.png
  • poetry.lock
  • polygott.png
  • pygame.png
  • pyproject.toml
  • python_beta.png
  • python_turtle.png
  • python.png
  • python3_beta.png
  • python3.png
  • pyxel.png
  • qbasic.png
  • quil.png
  • rails.png
  • raku.png
  • react_native.png
  • reactjs.png
  • reactre.png
  • reactts.png
  • reason_nodejs.png
  • reason.png
  • requirements.txt
  • riddlejs.png
  • rlang.png
  • roy.png
  • ruby.png
  • rust.png
  • scheme.png
  • sinatra.png
  • sqlite.png
  • static.png
  • swift.png
  • tcl.png
  • tkinter.png
  • Tkinter.png
  • typescript.png
  • unlambda.png
  • wasm.png
  • web_project.png
main.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import replit; replit.clear()
import json
from cairosvg import svg2png
from PIL import Image
import requests
import os
import sys


with open("lang_icons.json", "r") as f:
    imgs = json.loads(f.read())

"""
for name, svgurl in imgs.items():
    if not svgurl.startswith("https://") and not svgurl.startswith("http://"):
        assert svgurl.startswith("/")
        imgs[name] = "https://repl.it" + svgurl
        print(f"Fixed {svgurl}, now {imgs[name]}")
with open("lang_icons.json", "w") as f:
    json.dump(imgs, f)
"""


print()


def process_svg(url, name):
    print(f"{name}: requesting {url}")
    r = requests.get(url)
    r.raise_for_status()
    svg = r.text
    print(f"{name}: converting")
    filename = f"/home/runner/{name}.png"
    svg2png(bytestring=svg, write_to=filename)
    print(f"{name}: saved {filename}")


def save_file(url, name):
    print(f"{name}: requesting {url}")
    r = requests.get(url)
    r.raise_for_status()
    print(f"{name}: saving")
    filename = f"/home/runner/{name}.png"
    with open(filename, "wb+") as f:
        f.write(r.content)
    print(f"{name}: saved {filename}")


def download():
    print(f"Processing {len(imgs)} imgs")
    for name, url in imgs.items():
        if not url.endswith('.svg'):
            print(f"Img is not svg! {url}")
            try:
                filetype = url.split(".")[-1]
            except IndexError:
                filetype = "?"
            print(f"Filetype is probably {filetype}")
            if filetype == "png":
                print("Detected png, saving")
                save_file(url, name)
            else:
                while True:
                    action = input("c for convert, s for save, n for skip: ")
                    if action.startswith("c"):
                        process_svg(url, name)
                        break
                    elif action.startswith("s"):
                        save_file(url, name)
                        break
                    elif action.startswith("n"):
                        break
        else:
            process_svg(url, name)


def resize():
    warnings = []
    print("\nResizing images...")
    for fname in os.listdir("."):
        if not fname.endswith(".png"):
            continue
        print(f"{fname}: opening")
        target = 512
        img = Image.open(fname)
        if img.size[0] != img.size[1]:
            warnings.append(f"WARNING: {fname} is not a square: {img.size}")
        if img.size[0] >= target and img.size[1] >= target:
            print(f"{fname} already big enough: {img.size}")
        # calculate scale percentages
        #wpercent = (target/float(img.size[0]))
        #hsize = int((float(img.size[1])*float(wpercent)))
        #img = img.resize((target,hsize), Image.ANTIALIAS)
        img = img.resize((target, target), Image.ANTIALIAS)
        print(f"{fname}: Saving, size is {img.size}")
        os.remove(fname)
        img.save(fname)
    print("\n")
    print("\n".join(warnings))


if input("clean? ").lower().startswith("y"):
    print("cleaning files")
    for f in os.listdir("."):
        if f.endswith(".png"):
            os.remove(f)

if input("dl? ").lower().startswith("y"):
    download()

if input("resize? ").lower().startswith("y"):
    resize()