repl.it
@Scoder12/

repl line counter

Python

No description

fork
loading
Files
  • main.py
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
import requests
from urllib.parse import quote
from getpass import getpass

s = requests.Session()
api_url = "https://crosis-http-api.scoder12.repl.co/api/v1/"

def count_lines(text):
    return len([i for i in text.replace("\r", "").split("\n") if i.strip()])


def get_files_dirs(base, exclude=".upm,.npm,poetry.lock,pyproject.toml,requirements.txt,temp,__pycache__"):
    r = s.get(base + "/files/list?exclude=" + quote(exclude))
    r.raise_for_status()
    data = r.json()
    return data["files"], data["dirs"]

def get_file_data(base, fname):
    return s.get(base + "/files/read?raw=1&file=" + quote(fname)).text

def main():
    total_lines = 0
    crosiskey = getpass("Enter crosis key (https://devs.turbio.repl.co): ")
    s.cookies["crosis"] = crosiskey
    base = api_url + input("Enter repl id or name in the form of @user/repl: ")
    print("Listing files...")
    files, dirs = get_files_dirs(base)
    print("Reading files...")
    for fname in files:
        lines = count_lines(get_file_data(base, fname))
        print(fname, ": ", lines, sep="")
        total_lines += lines
    print("\nAnd the grand total is: ")
    print(total_lines, "lines")

if __name__ == "__main__":
    main()
Fetching token
?