-
Notifications
You must be signed in to change notification settings - Fork 4
/
tools.py
44 lines (36 loc) · 833 Bytes
/
tools.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
import os, shutil
from urllib.request import urlopen, urlretrieve
sep = os.path.sep
ope = os.path.exists
opj = os.path.join
def PathOrUrl(inpt):
# If path return True else it is assumed a url
if ope(inpt):
return True
try:
urlopen(inpt)
except:
raise TypeError('Boolean Required!')
return False
def Download(url):
pic = 'temp\\img.png'
try:
urlretrieve(url , pic)
return pic
except:
raise ConnectionError
def Rename(name):
if not name:
name = 'Sample'
for i in os.listdir():
if name + '.gif' == i:
name += '1'
return name
def Clean():
try:
shutil.rmtree('temp')
except:
pass
def Log(text, switch):
if switch:
print(text)