summaryrefslogtreecommitdiff
path: root/converters/links_to_gemini.py
blob: 8e401da8ad538ad10d2952fd184b71156d6c2338 (plain)
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
import os
from os import walk
import os.path

def convert_links_to_gemini(domain):
    for file in os.listdir("output/gemini"):
        convert_file_links(file)
    return("links are converted to gemini (3/3)")

def convert_file_links(file):
        processed = ""
        f = open("output/gemini/" + file, "r")
        for line in f.readlines():
            if ".html" in line and "http" not in line: # or domain in line:
                line = line.replace("html", "gmi")
                url = line.split(" ")[1]

                link = url.split("/")[-1]

                line = line.replace(str(url), str(link))

                processed += line

            else:
                processed += line
        f.close()
        f = open("output/gemini/" + file, "w")
        f.write(processed)
        f.close()