-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
85 lines (48 loc) · 1.89 KB
/
data.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
import re
import requests
import json
from flask import Flask , render_template , request
from bs4 import BeautifulSoup
userData = input("Enter the city name")
# print(userData)
event_title = []
def remove_html_tags(textList):
"""Remove html tags from a string"""
clean = re.compile('<.*?>')
textList = list(map(lambda i:re.sub(clean, '', str(i)),textList))
clean = re.compile('\s+')
textList = list(map(lambda i:re.sub(clean, ' ', str(i)),textList))
return textList
def cityEvents():
eventsUrl = "https://allevents.in/" + userData + "/all?ref=cityhome-popular"
# print(eventsUrl)
eventFile = "Event.json"
eventData = []
eventResponse = requests.get(eventsUrl)
# print(eventResponse)
eveSoup = BeautifulSoup(eventResponse.text , "lxml")
try:
event = eveSoup.find_all("div" , {"class":"events-style-resgrid default-event-list"})
# print(event)
except AttributeError:
pass
for events in event:
title = remove_html_tags(events.find_all( class_ = "title")[0:5])
# print(title[1])
date = remove_html_tags(events.find_all( class_ = "meta-left")[0:5])
venue = remove_html_tags(events.find_all( class_ = "up-venue toh")[0:5])
ticket = remove_html_tags(events.find_all( class_ = "tick-price")[0:5])
event_title.append(title)
# combine = title + date + venue + ticket
# print(final)
# eventData.append({
# "Title":remove_html_tags(title),
# "Date": remove_html_tags(date),
# "Venue":remove_html_tags(venue),
# "Ticket":remove_html_tags(ticket)
# })
# with open(eventFile,"w") as jsonFile:
# jsonFile.write(json.dumps( eventData, indent=4))
# print(eventData)
print(event_title)
cityEvents()