-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort.py
107 lines (70 loc) · 2.93 KB
/
sort.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
import os
import sys
import winshell
import win32com.client
import string
shell = win32com.client.Dispatch('WScript.Shell')
userDesktop = winshell.desktop()
main_path = (os.path.join(userDesktop, "KARTY PRZEGLĄDARKA"))
print(os.path.abspath(os.getcwd()))
def main():
# Check command-line arguments
if len(sys.argv) != 2:
sys.exit("Usage: python sort.py name_file.txt")
if not os.path.exists(os.path.abspath(sys.argv[1])):
print("Plik z danymi (.txt) nie istnieje lub zła nazwa!")
else:
try:
file_to_open= os.path.abspath(sys.argv[1])
#file_to_open=os.path.join(main_path, sys.argv[1])
with open(file_to_open, encoding="utf8") as f:
i=0
while True:
i+=1
link = f.readline()
if not link:
break
print(i)
category=what_category(link)
print(link, "\n", category, "\n\n")
#safe_link(link, category)
except:
print("Plik nie istnieje lub zapisany w złym miejscu!\n Problem z folderami")
def what_category(link):
categories = {"youtube" : ["youtube"],
"shopping" : ["allegro","aliexpress", "ceneo", "empik", "lidl", "sklep", "jysk", "ikea", "biedronka"],
"shopping beauty" : ["fragrantica","perfumy" , "makeup", "ezebra", "ekobieca","drogerienatura", "drogeria", "apteka", "pigment"],
"shopping other" : ["pinsola", "zalando", "sznur", "stradivarius", "zara", "hm","reserved","sinsay"],
"programming": ["geek","instructables","skillshot", "github", "cpp", "dev", "hack", "stackoverflow", "python"],
"programming web" : ["css", "template", "bootstrap" ],
"programming electronics" : ["forbot","openeeg", "raspberry", "arduino", "skillshot"],
"learn":["programming", "edx", "course", "learn", "english", "ai", "marki", "learn", "artificial", "education", "experiments", "bigdata", "wikipedia", "academy", "history"],
"our_home": ["stodola"],
"media" : ["mail", "facebook", "filmweb", "bank", "hbo", "amazon","netflix"],
"projects": ["canva", "docs", "colorland"],
"mems" : ["jebzdzidy", "jbzd", "kwejk", "9gag"]}
for category in categories:
for word in categories[category]:
if word in link:
return category
return "other"
def safe_link(target, category):
characters=["<",">",":","/","\"","\\","|","?","*","+","=","https", " "]
# name = target.replaceAll("<>:\"/\\|?*", "")
name=target
for ch in characters:
name = name.replace(ch,"")
if len(name)>=127:
name = name[:127] # trimm to len 260\255\127
name = name.replace(" ","")
if " " in category:
category=category.split()
category=os.path.join(category[0], category[1])
name_link=name.strip()+".url"
path_all = (os.path.join(main_path, category, name_link))
#target = r"https://www.codespeedy.com/create-the-shortcut-of-any-file-in-windows-using-python/"
shortcut = shell.CreateShortCut(path_all)
shortcut.TargetPath = target
shortcut.save()
if __name__ == "__main__":
main()