-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
188 lines (156 loc) · 6.42 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
from flask import Flask,render_template
from bs4 import BeautifulSoup
import requests
import json
import datetime
from image_generator import Pil
from insta_post_uploader import Insta_Post
app = Flask(__name__)
def date_converter(date):
date = date.lstrip()
month = {'Jan': '01',
'Feb': '02',
'Mar': '03',
'Apr': '04',
'May': '05',
'Jun': '06',
'Jul': '07',
'Aug': '08',
'Sep': '09',
'Oct': '10',
'Nov': '11',
'Dec': '12'
}
try :
str_month, s_date, garbage, e_date = date.split(' ')
num_month = month[str_month]
s_date = s_date.strip("th")
s_date = s_date.strip("st")
s_date = s_date.strip("nd")
s_date = s_date.strip("rd")
e_date = e_date.strip("th")
e_date = e_date.strip("st")
e_date = e_date.strip("nd")
e_date = e_date.strip("rd")
std_s_date = f"2021-{num_month}-{s_date}"
std_e_date = f"2021-{num_month}-{e_date}"
return [std_s_date, std_e_date]
except :
return [" ", " "]
def today_date() :
t_date = datetime.datetime.today()
month = t_date.month
year = t_date.year
day = t_date.day
date = f"{year}-{month}-{day}"
return date
def month_generator(date):
month = {'Jan': '01',
'Feb': '02',
'Mar': '03',
'Apr': '04',
'May': '05',
'Jun': '06',
'Jul': '07',
'Aug': '08',
'Sep': '09',
'Oct': '10',
'Nov': '11',
'Dec': '12'
}
return month[date]
@app.route('/')
def hackerEarth():
Events = []
#Code For MLH scrapping( Contributed By : Dhairya Patel)
URL1 = requests.get("https://mlh.io/seasons/2021/events")
if URL1.status_code != 200:
print("Sorry an error occured. Please try Again Later:)")
else:
soup = BeautifulSoup(URL1.text, 'html.parser')
final_details = []
for card in soup.find_all('div', class_='event'):
event_name = card.find('h3', class_='event-name').text
t_date = card.find('p', class_='event-date').text
parent = card.find('div', class_='image-wrap')
image_wrap = parent.find('img').get('src')
link = card.find('a', class_='event-link').get('href')
registration_date = card.find_all('meta')
new_date_format = date_converter(t_date)
if new_date_format[0] != " " and new_date_format[1] != " ":
current_date = today_date()
date = new_date_format[0].split("-")
date_curr_list = current_date.split("-")
d1 = datetime.datetime(int(date[0]), int(date[1]), int(date[2]))
d2 = datetime.datetime(int(date_curr_list[0]), int(date_curr_list[1]), int(date_curr_list[2]))
if d1 >= d2:
temp_details = [event_name, new_date_format[0], link, image_wrap, new_date_format[1], "MLH(Multi League Hacking)"]
Events.append(temp_details)
else:
break
else:
continue
#Code For HackerEarth scrapping( Contributed By : Dev Pandya)
URL = requests.get('https://www.hackerearth.com/challenges/').text
soup = BeautifulSoup(URL, 'html.parser')
Upcoming_events = soup.find('div', class_='upcoming')
Event_names = [] # newly added
for card in Upcoming_events.find_all('div', class_='challenge-card-modern'):
event_temp = card.find('div', class_='challenge-name').text
event = event_temp.split('\n')
date_temp1 = card.find('div', class_='date').text
date_temp2 = date_temp1.split(' ')
date_temp3 = date_temp2[1].split(',')
month = month_generator(date_temp2[0])
date_passed = f"2021-{month}-{date_temp3[0]}"
time = f"{date_temp2[2]} {date_temp2[3]}"
image = card.find('div', class_='event-image').get('style').split('url(\'')
Link_front = "https://www.hackerearth.com"
Link_tail = card.a.get('href')
Link = Link_front + Link_tail
img = image[1].split('\');')
if event[1] == "Java Developer Hiring Challenge - May21":
continue
else:
temp = [event[1], date_passed, Link, img[0], "No Data","HackerEarth"]
Events.append(temp)
Event_names.append(event[1])
req = requests.get('https://codeforces.com/api/contest.list')
received = req.text
data = json.loads(received)
data_result = data['result']
for x in data_result:
if (x['relativeTimeSeconds'] < 0):
name = x['name'] # Name Var
start_date = datetime.datetime.today() + datetime.timedelta(seconds=-1 * x['relativeTimeSeconds'])
s_date = f"{start_date.year}-{start_date.month}-{start_date.day}" # Start Date Var
end_date = datetime.datetime.today() + datetime.timedelta(
seconds=x['durationSeconds'] + (-1 * x['relativeTimeSeconds']))
e_date = f"{end_date.year}-{end_date.month}-{end_date.day}" # End Date Var
website = "https://codeforces.com/contests/page/1" # Website URL Var
temp_event_1 = [name, s_date, website, "static\images\\3-01.jpg", e_date, "CodeForces"]
Events.append(temp_event_1)
# Code For HackClub Scrapping (Contributed By : Pruthvik Sheth)
url_hackclub = 'https://hackathons.hackclub.com/api/events/upcoming'
response1 = requests.get(url_hackclub)
if response1.status_code != 200:
print("Sorry an error occured. Please try Again :)")
else:
strResponse = response1.text
data = json.loads(strResponse)
for x in data:
s_date = x['start'].split('T')
e_date = x['end'].split('T')
temp_event = [x['name'], s_date[0], x['website'], x['logo'], e_date[0],"HackClub"]
Events.append(temp_event)
return render_template('index.html', events=Events, length=len(Events))
app.run(debug = True)
# This part will create insta post
count = 0
for Event in Events:
if count==20:
break
else:
Pil(Event[0], Event[1], count)#This will create Images that you want your text on
count += 1
Insta_Post(5)#This will post 5 post on insta