mirror of
https://github.com/kristoferssolo/School.git
synced 2026-03-22 00:26:35 +00:00
Update folder structure
This commit is contained in:
29
november/task_241121/main.py
Normal file
29
november/task_241121/main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from audioop import add
|
||||
from ctypes import addressof
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
url = "https://en.wikipedia.org/wiki/Husky"
|
||||
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']}")
|
||||
else:
|
||||
print(":(")
|
||||
14579
november/task_241121/task_061021/book.txt
Normal file
14579
november/task_241121/task_061021/book.txt
Normal file
File diff suppressed because it is too large
Load Diff
44
november/task_241121/task_061021/kcagulis_061021.py
Normal file
44
november/task_241121/task_061021/kcagulis_061021.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# Author - Kristiāns Francis Cagulis
|
||||
# Date - 06.10.2021
|
||||
import re
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
||||
def read_book(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: "))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user