diff --git a/Header_readerTASK01WORK_LIBRARY_N2.py b/Header_readerTASK01WORK_LIBRARY_N2.py new file mode 100644 index 0000000..af507cc --- /dev/null +++ b/Header_readerTASK01WORK_LIBRARY_N2.py @@ -0,0 +1,11 @@ +from bs4 import BeautifulSoup +import requests +import pandas + +url = input('Enter an URL (starts from `http://`): ') +response = requests.get(url) +soup = BeautifulSoup(response.content,"html.parser") + +for i in soup.find_all("h2"): + print(i.response) + diff --git a/Mood_in_textTASK02WORK_LIBRARY_N2.py b/Mood_in_textTASK02WORK_LIBRARY_N2.py new file mode 100644 index 0000000..0ea3599 --- /dev/null +++ b/Mood_in_textTASK02WORK_LIBRARY_N2.py @@ -0,0 +1,6 @@ +from colorama import Fore, init +import emoji +init() +mood_choise = int(input("1 joyful mood \n2 grief mood \n3 excited mood \n4 exhausted mood \nhi!, How are you today:")) +if mood_choise == 1: + print(U+5350(Fore.Orange + ":")) \ No newline at end of file diff --git a/scripts/06_execution_time02.py b/scripts/06_execution_time02.py new file mode 100644 index 0000000..90a2445 --- /dev/null +++ b/scripts/06_execution_time02.py @@ -0,0 +1,48 @@ +""" +ExecutionTime + +This class is used for timing execution of code. + +For example: + + timer = ExecutionTime() + print 'Hello world!' + 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() +my_list = [] +for num in range(1, 1000000): + if num % 2 == 0: + my_list.append(random.randint(1, 888898)) +print("Finished in {:.2f} seconds".format(timer.duration())) \ No newline at end of file diff --git a/scripts/08_basic_email_web_crawler02.py b/scripts/08_basic_email_web_crawler02.py new file mode 100644 index 0000000..f8f3dd8 --- /dev/null +++ b/scripts/08_basic_email_web_crawler02.py @@ -0,0 +1,30 @@ +from bs4 import BeautifulSoup +import requests + +# get url + +url = input('Enter a URL (include `http://`): ') +response = requests.get(url) +html = response.text +soup = BeautifulSoup(html,"html.parser") +print(html) + +links = [] +for i in soup.find_all("a",href=True): + links.append(1) + print("link is found: ", i) +# 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) + + +# print the number of links in the list +print("\nFound {} links".format(len(links))) +for email in emails: + print(email) diff --git a/scripts/33_country_codeUPDATED_NikVor.py b/scripts/33_country_codeUPDATED_NikVor.py new file mode 100644 index 0000000..4c937e7 --- /dev/null +++ b/scripts/33_country_codeUPDATED_NikVor.py @@ -0,0 +1,84 @@ +# 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 json +import csv + +def getData(): + with open("33_country_codes.json", "r") as file: + data = json.load(file) # Correcting json.load to actually load the data + countryCodes = [] + countries = [] + continents = [] + + for country in data["country"]: + countryCodes.append(country["countryCode"]) + countries.append(country["countryName"]) + continents.append(country["continentName"]) + + return countryCodes, countries, continents + + +def saveCSV(countryCodes, countries, continents): + with open("MyCSV.csv", "w", newline="") as file: + writer = csv.writer(file) + writer.writerow(["country code", "country name", "continent name"]) + + for i in range(len(countries)): + writer.writerow([countryCodes[i], countries[i], continents[i]]) + + +# Get country data +countryCodes, countries, continents = getData() + +# Save data to CSV +saveCSV(countryCodes, countries, continents) \ No newline at end of file diff --git a/weather_request.py b/weather_request.py new file mode 100644 index 0000000..a15579e --- /dev/null +++ b/weather_request.py @@ -0,0 +1,9 @@ +api_key = "2d76fdaa7e7b3f369a9010894092ada4" +url = "https://api.openweathermap.org/data/2.5/weather" + +city = input("Put your link") + +params = { + "IPs":api_key,S + } +request.get(url,city) \ No newline at end of file