From 5d0b863d0c08b9f0f5a82a34494738be74677e1a Mon Sep 17 00:00:00 2001 From: peisje Date: Mon, 12 May 2025 14:11:56 +0300 Subject: [PATCH 1/6] Add files via upload --- scripts/06_execution_time.py | 37 +++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/scripts/06_execution_time.py b/scripts/06_execution_time.py index 9614bbd..581bb1c 100755 --- a/scripts/06_execution_time.py +++ b/scripts/06_execution_time.py @@ -14,21 +14,40 @@ import time import random - +# +# +# class ExecutionTime: +# def __init__(self): +# self.start_time = time.time() +# +# def duration(self): +# return time.time() - self.start_time +# +# +# # ---- run code ---- # +# +# +# timer = ExecutionTime() +# sample_list = list() +# my_list = [random.randint(1, 888898) for num in +# range(1, 1000000) if num % 2 == 0] +# print('Finished in {} seconds.'.format(timer.duration())) class ExecutionTime: def __init__(self): self.start_time = time.time() - + def duration(self): return time.time() - self.start_time + +timer = ExecutionTime() +sample_list = [] +for i in range(1, 1000000): + if i % 2 == 0: + sample_list.append(random.randint(1, 888898)) + +for i in range(10): + print("1111") -# ---- run code ---- # - - -timer = ExecutionTime() -sample_list = list() -my_list = [random.randint(1, 888898) for num in - range(1, 1000000) if num % 2 == 0] print('Finished in {} seconds.'.format(timer.duration())) From d62656239947c5b8fb959d872663465de859aa16 Mon Sep 17 00:00:00 2001 From: peisje Date: Mon, 12 May 2025 14:15:51 +0300 Subject: [PATCH 2/6] Refactored code: for-loop for beginner readability From c9d1f0516edea94dc607650da119585b9ca4b146 Mon Sep 17 00:00:00 2001 From: peisje Date: Mon, 12 May 2025 14:17:52 +0300 Subject: [PATCH 3/6] Refactored code: for-loop for beginner readability From d90d1ca228d0fc28cd390b00688d11fea9d3a4b7 Mon Sep 17 00:00:00 2001 From: peisje Date: Mon, 12 May 2025 14:52:15 +0300 Subject: [PATCH 4/6] Update 08_basic_email_web_crawler.py --- scripts/08_basic_email_web_crawler.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/scripts/08_basic_email_web_crawler.py b/scripts/08_basic_email_web_crawler.py index b56c747..0d4da73 100755 --- a/scripts/08_basic_email_web_crawler.py +++ b/scripts/08_basic_email_web_crawler.py @@ -1,21 +1,20 @@ +from bs4 import BeautifulSoup import requests -import re + # get url url = input('Enter a URL (include `http://`): ') +response = requests.get(url) +html = response.text +soup = BeautifulSoup(html, "html.parser") +print(html) -# connect to the url -website = requests.get(url) - -# read html -html = website.text - -# use re.findall to grab all the links -links = re.findall('"((http|ftp)s?://.*?)"', html) -emails = re.findall('([\w\.,]+@[\w\.,]+\.\w+)', html) - +links = [] +for i in soup.find_all("a",href= True): + links.append(i) + print("leitud link: ", i) # print the number of links in the list -print("\nFound {} links".format(len(links))) -for email in emails: - print(email) +# print("\nFound {} links".format(len(links))) +# for email in emails: +# print(email) From 112c39cbc745953406f8f007908b7b85199efbe1 Mon Sep 17 00:00:00 2001 From: peisje Date: Wed, 14 May 2025 10:15:09 +0300 Subject: [PATCH 5/6] Update 18_zipper.py --- scripts/18_zipper.py | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/scripts/18_zipper.py b/scripts/18_zipper.py index 43c956d..18d246d 100755 --- a/scripts/18_zipper.py +++ b/scripts/18_zipper.py @@ -3,18 +3,35 @@ from zipfile import ZipFile -# set file name and time of creation +# # set file name and time of creation +# today = datetime.now() +# file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip' +# dir_name = 'tmp/' # update path +# +# +# def zipdir(path, zip): +# for root, dirs, files in os.walk(path): +# for file in files: +# zip.write(os.path.join(root, file)) +# +# if __name__ == '__main__': +# zipfile = ZipFile(file_name, 'w') +# zipdir(dir_name, zipfile) +# zipfile.close() + + + today = datetime.now() file_name = 'zipper_' + today.strftime('%Y.%m.%dh%H%M') + '.zip' dir_name = 'tmp/' # update path - -def zipdir(path, zip): - for root, dirs, files in os.walk(path): +def add_folder_to_zip(folderPath,zipFIle): + for root,dirs,files in os.walk(folderPath): for file in files: - zip.write(os.path.join(root, file)) - -if __name__ == '__main__': - zipfile = ZipFile(file_name, 'w') - zipdir(dir_name, zipfile) - zipfile.close() + print(file) + print(root) + full_path=os.path.join.join(root,file) + zipFile.write(full_path) + +with ZipFile("test_zip.zip","w") as my_zip: + add_folder_to_zip("Desktop",my_zip) From 3155478c01f0e94883d011205aaa23a39d62ec27 Mon Sep 17 00:00:00 2001 From: peisje Date: Thu, 15 May 2025 10:54:39 +0300 Subject: [PATCH 6/6] Add files via upload --- scripts/33_country_code.py | 106 +++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/scripts/33_country_code.py b/scripts/33_country_code.py index 134236c..dec6b46 100644 --- a/scripts/33_country_code.py +++ b/scripts/33_country_code.py @@ -1,51 +1,55 @@ -import csv -import sys -import json - -""" -Example usage: - -$ python 33_country_code.py 33_sample_csv.csv 33_country_codes.json -""" - - -def get_data(csv_file, json_file): - countryCodes = [] - countryNames = [] - continentNames = [] - with open(csv_file, 'rt') as file_one: - reader = csv.reader(file_one) - with open(json_file) as file_two: - json_data = json.load(file_two) - all_countries = json_data["country"] - for csv_row in reader: - for json_row in all_countries: - if csv_row[0] == json_row["countryCode"]: - countryCodes.append(json_row["countryCode"]) - countryNames.append(json_row["countryName"]) - continentNames.append(json_row["continentName"]) - - return [ - countryCodes, - countryNames, - continentNames - ] - - -def write_data(array_of_arrays): - with open('data.csv', 'wt') as csv_out: - writer = csv.writer(csv_out) - rows = zip( - array_of_arrays[0], - array_of_arrays[1], - array_of_arrays[2] - ) - for row in rows: - writer.writerow(row) - - -if __name__ == '__main__': - csv_file_name = sys.argv[1] - json_file_name = sys.argv[2] - data = get_data(csv_file_name, json_file_name) - write_data(data) +import csv, json + + +with open("33_country_codes.json","r") as file: + data=json.load(file) + print(data) + + +codes = {"country": [ + { + "countryCode": "AD", + "countryName": "Andorra", + "continentName": "Europe" + }, + { + "countryCode": "AE", + "countryName": "United Arab Emirates", + "continentName": "Asia" + }, + { + "countryCode": "AF", + "countryName": "Afghanistan", + "continentName": "Asia" + } + ] + } + +codesc=[] +countries=[] +continrnt=[] + + +print(codes["country"][0]["countryName"]) + +for code in data["country"]: + codesc.append(code["countryCode"]) + countries.append(code["countryName"]) + continrnt.append(code["continentName"]) + + + +print(codesc) +print(countries) +print(continrnt) + + +def save_csv(codesc, countries, continrnt): + with open("myCSV.csv", "w", newline = "") as file: + writer=csv.writer(file) + writer.writerow(["country Code","country Name","continent Name"]) + print(codesc, countries, continrnt) + for i in range(1, len(countries)): + writer.writerow([codesc[i], countries[i], continrnt[i]]) + +save_csv(codesc,countries,continrnt)