-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbios_multi.py
95 lines (74 loc) · 3.23 KB
/
bios_multi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
os.system('clear')
import threading
import requests, sys
from bs4 import BeautifulSoup
import csv, xlsxwriter
import json, datetime
urls = ["https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=24-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=25-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=26-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=27-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=28-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=29-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=30-08-2020","https://www.pathe.nl/bioscoop/utrechtleidscherijn?date=31-08-2020"]
csv_file = open("/Users/MWK/Desktop/bios/bios.csv","w")
fieldnames = ['titel', 'Start tijd', 'img_url']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
xlsx = '/Users/MWK/Desktop/bios/bios.xlsx'
workbook = xlsxwriter.Workbook(xlsx)
worksheet = workbook.add_worksheet()
N1AKD = open("/Users/MWK/Desktop/bios/bios.json","w")
jsonx = open("/Users/MWK/Desktop/bios/bios.json","w")
def do_shit(URL):
print(URL)
URL = "https://www.pathe.nl/bioscoop/utrechtleidscherijn"
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15'}
page = requests.get(URL, headers=headers )
soup = BeautifulSoup(page.content, 'html.parser')
body = soup.find(id="js-cinema-schedule")
N1AKD.writelines("[")
items = body.find_all("div", class_="schedule-simple__item")
count = 1
datas=[]
Naam = 0
Start_tijd = 1
img_url = 2
for item in items:
p_data = item.find("a", class_="poster")
print("\n"+p_data["title"])
start_times = item.find("span", class_="schedule-time__start")
print("De film begint om: "+start_times.get_text())
hd_img = p_data.find("img")
print("\n"+hd_img["src"])
worksheet.write(count, Naam, str(p_data["title"]))
worksheet.write(count, Start_tijd, str(start_times.get_text()))
worksheet.write(count, img_url, str(hd_img["src"]))
writer.writerow({'titel': p_data["title"] , 'Start tijd': start_times.get_text(), 'img_url': hd_img["src"]})
data = {}
data["title"] = p_data["title"]
data["tijd"] = start_times.get_text()
data["img_url"] = hd_img["src"].replace(" ", "%20")
data["id"] = count
json.dumps(data)
datas.append(data)
count += 1
def sortFunction(value):
return value["tijd"]
sorteds = sorted(json.loads(str(datas).replace("'", '"')), key=sortFunction)
jsonx.writelines(str(json.dumps(sorteds, indent=4)))
import time
start = time.time()
if __name__ == "__main__":
threads = list()
for URL in urls:
print("Gemaakt Theard")
x = threading.Thread(target=do_shit, args=(URL,))
threads.append(x)
x.start()
for index, thread in enumerate(threads):
print("Main : before joining thread %d.", URL)
thread.join()
print("Main : thread %d done", index)
end = time.time()
print("\n\n -- tijd hoelang het duurde -- \n")
print(end - start)
jsonx.close()
csv_file.close()
workbook.close()
N1AKD.close()