-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_hw_info.py
96 lines (71 loc) · 4.34 KB
/
get_hw_info.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
# Necessary libraries
import requests
import json
import time
import re
import os
def main( ):
with open( 'login_data.json' ) as login_data:
login = json.load( login_data )
if not login:
return
if len( login[ 'Usuario' ] ) < 2:
return
s = requests.Session( )
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
s.post( 'https://portal.p4ed.com/', data = login, headers = { 'User-Agent': user_agent } )
resp = s.get( 'https://portal.p4ed.com/Login/AutenticacaoPortalEdrosAlunos/0' )
login_token = re.search( r"'https:\/\/student\.p4ed\.com\/login\/loginbytoken\/(.+)?'", resp.text ).group( )
login_token = login_token[ 1 : -1 ]
s.get( login_token )
resp = s.get( 'https://student.p4ed.com/tarefas/dados/2/0' )
resp_json = json.loads( resp.text )
for i in range( len( resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ] ) ):
if len( resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ):
for j in range( len( resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ) ):
id = str( resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ][ j ][ "Id" ] )
if not os.path.exists( "images\\" + id + ".png" ):
img_resp = s.get( "https://student.p4ed.com/imagens2/obterimagemtarefa/" + id )
with open( "images\\" + id + ".png", 'wb' ) as outfile:
outfile.write( img_resp.content )
index = 1
while( True ):
resp = s.get( 'https://student.p4ed.com/tarefas/dados/2/' + str( index ) )
cur_json = json.loads( resp.text )
if len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ] ):
for i in range( len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ] ) ):
if len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ):
for j in range( len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ) ):
id = str( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ][ j ][ "Id" ] )
if not os.path.exists( "images\\" + id + ".png" ):
img_resp = s.get( "https://student.p4ed.com/imagens2/obterimagemtarefa/" + id )
with open( "images\\" + id + ".png", 'wb' ) as outfile:
outfile.write( img_resp.content )
resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ].insert( index * 10 + i, cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ] )
else:
break
index += 1
index -= 1
index2 = 0
while( True ):
resp = s.get( 'https://student.p4ed.com/tarefas/dados/3/' + str( index2 ) )
cur_json = json.loads( resp.text )
if ( len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ] ) ):
for i in range( len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ] ) ):
if len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ):
for j in range( len( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ] ) ):
id = str( cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ][ "Imagens" ][ j ][ "Id" ] )
if not os.path.exists( "images\\" + id + ".png" ):
img_resp = s.get( "https://student.p4ed.com/imagens2/obterimagemtarefa/" + id )
with open( "images\\" + id + ".png", 'wb' ) as outfile:
outfile.write( img_resp.content )
resp_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ].insert( index * 10 + i, cur_json[ "Dados" ][ "DadosPagina" ][ "Tarefas" ][ i ] )
else:
break
index += 1
index2 += 1
with open( 'result_data.json', 'w+', encoding = 'utf8' ) as result_file:
json.dump( resp_json, result_file )
result_file.close( )
if __name__ == '__main__':
main( )