Final changes and commit

This commit is contained in:
Kristofers Solo
2022-08-02 20:34:11 +03:00
parent db328c4350
commit 253802ac88
38 changed files with 1917 additions and 1708 deletions

View File

@@ -7,38 +7,42 @@ CHAPTERS = 61
# creates file with chapters and row numbers
def read_array(document):
with open(document, "r", encoding='utf-8') as book:
lines = [line.strip('\n') for line in book] # removes 'enter' characters
with open('array_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1):
line = lines.index(f"Chapter {i}") + 1 # finds all chapter indexes/lines
output.write(f"Line {line} - Chapter {i}\n") # writes line in file
with open(document, "r", encoding='utf-8') as book:
lines = [line.strip('\n')
for line in book] # removes 'enter' characters
with open('array_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1):
# finds all chapter indexes/lines
line = lines.index(f"Chapter {i}") + 1
output.write(f"Line {line} - Chapter {i}\n") # writes line in file
# creates file with chapter positions
def read_string(document):
with open(document, "r", encoding='utf-8') as book:
lines = book.read()
with open('str_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1):
_, position = re.finditer(rf"\bChapter {i}\b", lines) # finds all chapter positions
output.write(f"Position {position.start()} - Chapter {i}\n") # writes position in file
with open(document, "r", encoding='utf-8') as book:
lines = book.read()
with open('str_output.txt', 'w') as output:
for i in range(1, CHAPTERS + 1):
# finds all chapter positions
_, position = re.finditer(rf"\bChapter {i}\b", lines)
# writes position in file
output.write(f"Position {position.start()} - Chapter {i}\n")
def read_book(document):
read_array(document)
read_string(document)
read_array(document)
read_string(document)
def main():
try:
read_book("book.txt")
except:
try:
read_book("1342-0.txt")
except:
read_book(input("Ievadiet faila nosaukumu: "))
try:
read_book("book.txt")
except:
try:
read_book("1342-0.txt")
except:
read_book(input("Ievadiet faila nosaukumu: "))
if __name__ == '__main__':
main()
main()

View File

@@ -8,91 +8,95 @@ data = pd.read_csv("company_sales_data.csv")
def task_1():
plt.figure(figsize=(10, 6)) # (x, y)
x = range(len(data["month_number"])) # gets range of months
plt.plot(x, data["total_profit"]) # sets up the plot
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
plt.ylim(ymin=100000) # sets minimal y value
plt.figure(figsize=(10, 6)) # (x, y)
x = range(len(data["month_number"])) # gets range of months
plt.plot(x, data["total_profit"]) # sets up the plot
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
plt.ylim(ymin=100000) # sets minimal y value
set_labels("Company profit per month", "Month number", "Total profit")
set_labels("Company profit per month", "Month number", "Total profit")
plt.show()
plt.show()
def task_2():
plt.figure(figsize=(10, 6)) # (x, y)
plt.figure(figsize=(10, 6)) # (x, y)
x = range(len(data["month_number"])) # gets range of months
x = range(len(data["month_number"])) # gets range of months
data_list = list(data.columns)[1:-2] # gets and trims column names
data_list = list(data.columns)[1:-2] # gets and trims column names
for column in data_list:
plt.plot(x, data[column], lw=4, marker='o', ms=10) # ms = marker size
for column in data_list:
plt.plot(x, data[column], lw=4, marker='o', ms=10) # ms = marker size
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
set_labels("Sales data", "Month number", "Sales units in number")
set_labels("Sales data", "Month number", "Sales units in number")
new_data_list = list(map(lambda x: x.capitalize() + " Sales Data", data_list)) # capitalizes each word in list
plt.legend(new_data_list, loc='upper left', fontsize=15)
plt.show()
# capitalizes each word in list
new_data_list = list(
map(lambda x: x.capitalize() + " Sales Data", data_list))
plt.legend(new_data_list, loc='upper left', fontsize=15)
plt.show()
def task_3():
plt.figure(figsize=(10, 6)) # (x, y)
x = range(len(data["month_number"])) # gets range of months
plt.figure(figsize=(10, 6)) # (x, y)
x = range(len(data["month_number"])) # gets range of months
plt.scatter(x, data["toothpaste"], s=75) # sets up the plot
plt.grid(ls='dashed', lw=1.5) # sets grid line type and width
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
plt.scatter(x, data["toothpaste"], s=75) # sets up the plot
plt.grid(ls='dashed', lw=1.5) # sets grid line type and width
plt.xticks(x, data["month_number"], fontsize=15) # sets x value step
plt.yticks(fontsize=15)
set_labels("Toothpaste Sales data", "Month number", "Number of units Sold")
plt.legend(["Toothpaste Sales data"], loc='upper left', fontsize=15)
plt.show()
set_labels("Toothpaste Sales data", "Month number", "Number of units Sold")
plt.legend(["Toothpaste Sales data"], loc='upper left', fontsize=15)
plt.show()
def task_4():
items = ["facecream", "facewash"]
items = ["facecream", "facewash"]
data.plot(x="month_number", y=["facecream", "facewash"], kind='bar', figsize=(10, 6), fontsize=15)
data.plot(x="month_number", y=[
"facecream", "facewash"], kind='bar', figsize=(10, 6), fontsize=15)
plt.xticks(rotation=0) # rotates x lables to 0
plt.grid(ls='dashed', lw=1.5) # sets grid line type and width
plt.xticks(rotation=0) # rotates x lables to 0
plt.grid(ls='dashed', lw=1.5) # sets grid line type and width
set_labels("Facewash and Facecream Sales data", "Month number", "Sales units in number")
new_items_list = list(map(lambda x: x.capitalize() + " Sales Data", items))
plt.legend(new_items_list, loc='upper left', fontsize=15)
plt.show()
set_labels("Facewash and Facecream Sales data",
"Month number", "Sales units in number")
new_items_list = list(map(lambda x: x.capitalize() + " Sales Data", items))
plt.legend(new_items_list, loc='upper left', fontsize=15)
plt.show()
def set_labels(title: str, xlabel: str, ylabel: str):
plt.title(title, fontsize=15)
plt.xlabel(xlabel, fontsize=15)
plt.ylabel(ylabel, fontsize=15)
plt.title(title, fontsize=15)
plt.xlabel(xlabel, fontsize=15)
plt.ylabel(ylabel, fontsize=15)
def main():
task = input("""Ivēlieties uzdevumu:
task = input("""Ivēlieties uzdevumu:
1 - pirmais uzdevums
2 - otrais uzdevums
3 - trešais uzdevums
4 - ceturtais uzdevums
""")
if task == "1":
task_1()
elif task == "2":
task_2()
elif task == "3":
task_3()
elif task == "4":
task_4()
else:
print("Tika ievadīts nepareiz cipars")
if task == "1":
task_1()
elif task == "2":
task_2()
elif task == "3":
task_3()
elif task == "4":
task_4()
else:
print("Tika ievadīts nepareiz cipars")
if __name__ == '__main__':
main()
main()

View File

@@ -8,37 +8,37 @@ url = "https://www.ikea.lv/"
all_page = requests.get(url)
if all_page.status_code == 200:
page = BeautifulSoup(all_page.content, 'html.parser')
found = page.find_all(class_="itemBlock")
page = BeautifulSoup(all_page.content, 'html.parser')
found = page.find_all(class_="itemBlock")
info = []
item_array = []
for item in found:
item = item.findChild("div").findChild(class_="card-body")
info = []
item_array = []
for item in found:
item = item.findChild("div").findChild(class_="card-body")
item_name = item.findChild(class_="itemName")
item_name = item_name.findChild("div").findChild("h6")
item_name = item.findChild(class_="itemName")
item_name = item_name.findChild("div").findChild("h6")
item_array.append(item_name.string)
item_array.append(item_name.string)
price = item.findChild(class_="itemPrice-wrapper")
price = price.findChild("p").findChild("span")
price = item.findChild(class_="itemPrice-wrapper")
price = price.findChild("p").findChild("span")
try:
item_array.append(price.attrs["data-price"])
except:
item_array.append(price.attrs["data-pricefamily"])
try:
item_array.append(price.attrs["data-price"])
except:
item_array.append(price.attrs["data-pricefamily"])
all_facts = []
for facts in all_facts:
if len(facts) == 1:
all_facts.append(facts.string)
else:
atrasts = facts.findChildren("span")
for i in atrasts:
all_facts.append(i.string)
all_facts = []
for facts in all_facts:
if len(facts) == 1:
all_facts.append(facts.string)
else:
atrasts = facts.findChildren("span")
for i in atrasts:
all_facts.append(i.string)
item_array.append(all_facts)
info.append(item_array)
for ieraksts in info:
print(ieraksts)
item_array.append(all_facts)
info.append(item_array)
for ieraksts in info:
print(ieraksts)

View File

@@ -7,21 +7,22 @@ all_page = requests.get(url)
# print(all_page)
if all_page.status_code == 200:
print(":)")
page = BeautifulSoup(all_page.content, 'html.parser')
found = page.find(id="Etymology")
# print(found)
# print(found.constents)
# print(found.string)
found = page.find_all(class_="mw-headline")
# print(found)
found = page.find_all("li", class_="interlanguage-link")
# print(found)
found = page.find_all("a", class_="interlanguage-link-target")
# print(found)
for i in found:
# print(i.prettify())
if i.attrs["lang"] == "ru":
print(f"{i.attrs['lang']} \t {i.attrs['title']} \n {i.attrs['href']}")
print(":)")
page = BeautifulSoup(all_page.content, 'html.parser')
found = page.find(id="Etymology")
# print(found)
# print(found.constents)
# print(found.string)
found = page.find_all(class_="mw-headline")
# print(found)
found = page.find_all("li", class_="interlanguage-link")
# print(found)
found = page.find_all("a", class_="interlanguage-link-target")
# print(found)
for i in found:
# print(i.prettify())
if i.attrs["lang"] == "ru":
print(
f"{i.attrs['lang']} \t {i.attrs['title']} \n {i.attrs['href']}")
else:
print(":(")
print(":(")