-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintro.py
More file actions
49 lines (45 loc) · 1.51 KB
/
intro.py
File metadata and controls
49 lines (45 loc) · 1.51 KB
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
import requests
import os
import logging
log = logging.getLogger('project')
logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
def listfiles(username):
if os.path.exists(username):
files = os.listdir(username)
for file in files:
print(file)
else:
print("No FIles downloaded")
def download(url, name):
#url = 'https://www.python.org/static/opengraph-icon-200x200.png'
log.info("Started downloading:{}".format(url))
r = requests.get(url)
if not os.path.exists(name):
os.mkdir(name)
filename = name+'/'+url.split('/')[-1]
with open(filename, 'wb') as fp:
fp.write(r.content)
log.info("Download COmpleted and stored locally")
def processfile(filepath, usename):
try:
if os.path.exists(filepath):
with open(filepath, 'r') as fp:
for line in fp:
#validate
download(line, username)
else:
print('File path is wrong try again')
except Exception as e:
log.error("There was error:{}".format(str(e)))
print(e)
#download('https://www.python.org/static/opengraph-icon-200x200.png', 'pavan')
print("Welcome to File manager\n ----------------------\n")
username = input("Enter your username:")
option = int(input("\n1.List of downloads\n2.Download\nEnter your option:"))
if option == 2:
filepath = input('Enter filename:')
processfile(filepath, username)
elif option==1:
listfiles(username)
else:
print("Choose right option")