-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.py
69 lines (57 loc) · 2.07 KB
/
misc.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
import requests, re
from bs4 import BeautifulSoup
# Login to intranet
def login(email, password):
"""
This functions logs in to the intranet
Args:
email: your intranet emails
password: the password associated with your email
Returns: The current active session to stay logged id
"""
session = requests.Session()
login_page_response = session.get('https://intranet.alxswe.com/auth/sign_in')
soup = BeautifulSoup(login_page_response.text, 'html.parser')
authenticity_token = soup.find('input', attrs={'name': 'authenticity_token'})['value']
login_data = {
'user[email]': email,
'user[password]': password,
'authenticity_token': authenticity_token
}
login_url = 'https://intranet.alxswe.com/auth/sign_in'
response = session.post(login_url, data=login_data)
return session
# Extract planning data
def fetch_planning(session):
"""
This functions extracts the data from the planning
Args:
session: The current active sessions
Returns:
data: The planning data
"""
url = "https://intranet.alxswe.com/dashboards/batch_planning_data.json?calendar_view=1×hift=-60"
response = session.get(url)
data = response.text
return data
# Extract the ressources
def extract_resources(session, project_id):
"""
This functions extracts the ressources of
the current project
Args:
session: The current active session
project_id: The ID associated with the current
project
Returns:
The ressources links for the current project
"""
url = f'https://intranet.alxswe.com/projects/{project_id}'
response = session.get(url)
if "Tables" in response.text:
html_content = response.text
else:
exit(1)
ressources = re.findall(r'<li><a href="/rltoken/(.*?)" title="(.*?)"', html_content, re.DOTALL)
list_of_ress = [f"[{i[1]}](https://intranet.alxswe.com/rltoken/{i[0]})" for i in ressources]
return list_of_ress