From a7c994f79c2a58240b4faed42cece97edea2493d Mon Sep 17 00:00:00 2001 From: elinakotsur Date: Mon, 12 May 2025 14:12:56 +0300 Subject: [PATCH 1/4] refactered loop --- scripts/06_execution_time.py | 39 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/scripts/06_execution_time.py b/scripts/06_execution_time.py index 9614bbd..c871457 100755 --- a/scripts/06_execution_time.py +++ b/scripts/06_execution_time.py @@ -10,25 +10,42 @@ print 'Finished in {} seconds.'.format(timer.duration()) """ - - +# +# 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 =[] - -# ---- run code ---- # +for i in range(1, 1000000): + if i % 2 ==0: + sample_list.append(random.randint(1, 888898)) +print('Finished in {} seconds.'.format(timer.duration())) -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 9136597f9065396c4e66cf7584811c7b7f23bb77 Mon Sep 17 00:00:00 2001 From: elinakotsur Date: Mon, 12 May 2025 14:52:13 +0300 Subject: [PATCH 2/4] Add files via upload --- scripts/08_basic_email_web_crawler.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/scripts/08_basic_email_web_crawler.py b/scripts/08_basic_email_web_crawler.py index b56c747..4738d6e 100755 --- a/scripts/08_basic_email_web_crawler.py +++ b/scripts/08_basic_email_web_crawler.py @@ -1,21 +1,19 @@ +from bs4 import BeautifulSoup import requests -import re # get url url = input('Enter a URL (include `http://`): ') +response = requests.get(url) +html=response.text +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) +soup=BeautifulSoup(html,"html.parser") +# print the number of links in the list -# print the number of links in the list -print("\nFound {} links".format(len(links))) -for email in emails: - print(email) + +link = [] +for i in soup.find_all("a",href=True): + link.append(i) + print("leidnut link:",i) From 7afafa62eea9e06cee02ca05d6432df0644bb204 Mon Sep 17 00:00:00 2001 From: elinakotsur Date: Wed, 14 May 2025 10:13:19 +0300 Subject: [PATCH 3/4] Add files via upload --- scripts/18_zipper.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/scripts/18_zipper.py b/scripts/18_zipper.py index 43c956d..1a9c27f 100755 --- a/scripts/18_zipper.py +++ b/scripts/18_zipper.py @@ -3,18 +3,36 @@ 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)) + 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) -if __name__ == '__main__': - zipfile = ZipFile(file_name, 'w') - zipdir(dir_name, zipfile) - zipfile.close() From 062acff327bb416c2b65a6c29b3fc1bfa2617635 Mon Sep 17 00:00:00 2001 From: elinakotsur Date: Thu, 15 May 2025 10:55:05 +0300 Subject: [PATCH 4/4] Add files via upload --- scripts/33_country_code.py | 114 ++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/scripts/33_country_code.py b/scripts/33_country_code.py index 134236c..8d26ca2 100644 --- a/scripts/33_country_code.py +++ b/scripts/33_country_code.py @@ -1,51 +1,63 @@ -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("myCSV1.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) +