Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedamara1 committed Oct 18, 2020
1 parent 9b768a6 commit 9535981
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions automatingv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@
import io
import os
import os.path
from os import path


def main():

service = get_classroom_service()
courses = service.courses().list(pageSize=11).execute()
courses = service.courses().list(pageSize=12).execute()

for course in courses['courses']:

course_name = course['name']
course_id = course['id']

try:
if not (path.exists(course_name)):
os.mkdir('./' + course_name)
except OSError:
print("Creation of {} directory failed".format(course_name))
else:
print("Created {} directory ".format(course_name))
print("{} Already exists ".format(course_name))

anoncs = service.courses().announcements().list(
courseId=course_id).execute()
Expand Down Expand Up @@ -124,11 +123,13 @@ def download_annonc_files(announcements, course_name):
os.path.splitext(file_name)
)[1] #the extension exists in second elemnts of returned tuple
print(extension)
path_str = os.path.join('./', course_name, file_name)

if (valid(extension[1:])):
if (valid(extension[1:]) and not (path.exists(path_str))):
print(file_name)
download_file(file_id, file_name, course_name)
print("HAHAHA")
else:
print(file_name, "already exists")
except KeyError as e:
print("this announcement doesn't have any file to download")

Expand All @@ -145,22 +146,23 @@ def download_works_files(works, course_name):
extension = (
os.path.splitext(file_name)
)[1] #the extension exists in second elemnts of returned tuple
print(extension)
if (valid(extension[1:])):
path_str = os.path.join('./', course_name, file_name)
if ((valid(extension[1:]))
and not (path.exists(path_str))):
print(file_name)
download_file(file_id, file_name, course_name)
print("HAHAHA")
else:
print(file_name, "already exists")
except KeyError as e:
print("this work doesn't have any file to download")


def valid(ch):
return ch in [
'pdf', 'docx', 'pptx', 'png', 'jpg', 'html', 'css', 'js', 'java',
'class', 'txt', 'r', 'm'
'class', 'txt', 'r', 'm', ' sql'
]


#his
if __name__ == '__main__':
main()

0 comments on commit 9535981

Please sign in to comment.