Update dnet-stats.py
This commit is contained in:
1 parent
ae3fd6d916
commit
b3a4592cb8
1 file changed
+59
-51
+59
-51
@@ -1,55 +1,65 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests, sys
|
import requests, sys
|
||||||
|
|
||||||
if len(sys.argv) <= 1: # check to see if we have at least 1 argument
|
# Distributed.net participant search form
|
||||||
print( # and if not, print a help menu
|
searchUrl = 'https://stats.distributed.net/participant/psearch.php'
|
||||||
|
|
||||||
|
# Valid Distributed.net Projects (and associated ID)
|
||||||
|
validProjects = {
|
||||||
|
'RSA-56' : 3,
|
||||||
|
'RSA-64' : 5,
|
||||||
|
'RSA-72' : 8,
|
||||||
|
'OGR-24' : 24,
|
||||||
|
'OGR-25' : 25,
|
||||||
|
'OGR-26' : 26,
|
||||||
|
'OGR-27' : 27,
|
||||||
|
'OGR-28' : 28,
|
||||||
|
}
|
||||||
|
|
||||||
|
# Help menu
|
||||||
|
def printHelp():
|
||||||
|
print(
|
||||||
'\nUsage: dnet-stats.py [user] [project]\n' +
|
'\nUsage: dnet-stats.py [user] [project]\n' +
|
||||||
'\nOptional: [project], must be specified using a project id number.\n' +
|
'\nPROJECTs' +
|
||||||
'\n=====Distributed.net Projects=====' +
|
'\n========' +
|
||||||
'\n3 = RSA-56 RC5 Encryption Challenge' +
|
'\n RSA-56 ' +
|
||||||
'\n5 = RSA-64 RC5 Encryption Challenge' +
|
'\n RSA-64 ' +
|
||||||
'\n8 = RSA-72 RC5 Encryption Challenge' +
|
'\n RSA-72 ' +
|
||||||
'\n24 = OGR-24 Optimal Golomb Rulers' +
|
'\n OGR-24 ' +
|
||||||
'\n25 = OGR-25 Optimal Golomb Rulers' +
|
'\n OGR-25 ' +
|
||||||
'\n26 = OGR-26 Optimal Golomb Rulers' +
|
'\n OGR-26 ' +
|
||||||
'\n27 = OGR-27 Optimal Golomb Rulers' +
|
'\n OGR-27 ' +
|
||||||
'\n28 = OGR-28 Optimal Golomb Rulers' +
|
'\n OGR-28 ' +
|
||||||
'\n===================================\n'
|
'\n========\n'
|
||||||
)
|
)
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
# distributed.net participant search form
|
# If no arguments are given, display Help Menu
|
||||||
dnet_url = 'https://stats.distributed.net/participant/psearch.php'
|
if len(sys.argv) <= 2:
|
||||||
|
print('\nError: Please specify user and project.')
|
||||||
|
printHelp()
|
||||||
|
|
||||||
### distributed.net projects ###
|
# get username from user input
|
||||||
#dnet_project_id = 24 # OGR-24 Optimal Golomb Rulers
|
myUser = sys.argv[1]
|
||||||
#dnet_project_id = 25 # OGR-25 Optimal Golomb Rulers
|
|
||||||
#dnet_project_id = 26 # OGR-26 Optimal Golomb Rulers
|
|
||||||
#dnet_project_id = 27 # OGR-27 Optimal Golomb Rulers
|
|
||||||
#dnet_project_id = 28 # OGR-28 Optimal Golomb Rulers
|
|
||||||
#dnet_project_id = 3 # RSA Labs' 56bit RC5 Encryption Challenge
|
|
||||||
#dnet_project_id = 5 # RSA Labs' 64bit RC5 Encryption Challenge
|
|
||||||
dnet_project_id = 8 # RSA Labs' 72bit RC5 Encryption Challenge
|
|
||||||
|
|
||||||
if len(sys.argv) == 2:
|
# get project from user input
|
||||||
print('\nNo project id specified so defaulting to ' + str(dnet_project_id) + '.')
|
myProject = sys.argv[2].upper()
|
||||||
|
|
||||||
valid_projects = ['3', '5', '8', '24', '25', '26', '27', '28', '205']
|
|
||||||
|
|
||||||
|
# if we have all arguments needed, proceed...
|
||||||
if len(sys.argv) == 3:
|
if len(sys.argv) == 3:
|
||||||
x = sys.argv[2]
|
# ensure the project argument is a valid project
|
||||||
if x in valid_projects:
|
if sys.argv[2].upper() in ['RSA-56','RSA-64','RSA-72','OGR-24','OGR-25','OGR-26','OGR-27','OGR-28']:
|
||||||
dnet_project_id = sys.argv[2]
|
# if it is valid, store the Project ID into a variable
|
||||||
|
projectId = validProjects[sys.argv[2].upper()]
|
||||||
else:
|
else:
|
||||||
print('\n' + sys.argv[2] + ' is not a valid project id.\n')
|
# otherwise, let the user know their project was not valid
|
||||||
|
print('\nError: ' + sys.argv[2].upper() + ' is not a valid project.')
|
||||||
|
printHelp()
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
dnet_search_text = sys.argv[1] # store the user argument into a variable
|
data = {'project_id':projectId,'st':myUser} # along with the project id
|
||||||
|
response = requests.post(searchUrl,data=data) # perfom a form post and get the response
|
||||||
data = {'project_id':dnet_project_id,'st':dnet_search_text} # along with the project id
|
|
||||||
response = requests.post(dnet_url,data=data) # perfom a form post and get the response
|
|
||||||
|
|
||||||
if response: # if we received a response
|
if response: # if we received a response
|
||||||
soup = BeautifulSoup(response.text, 'lxml') # load the response into BeautifulSoup
|
soup = BeautifulSoup(response.text, 'lxml') # load the response into BeautifulSoup
|
||||||
@@ -57,33 +67,31 @@ if response: # if we received a response
|
|||||||
summary = soup.find('td',class_='htitle').text.lstrip() # find summary
|
summary = soup.find('td',class_='htitle').text.lstrip() # find summary
|
||||||
|
|
||||||
if "Summary" in summary:
|
if "Summary" in summary:
|
||||||
print('\nUser: ' + dnet_search_text) # print user
|
print('\nUser: ' + myUser) # print user
|
||||||
summary = " ".join(summary.split()) # remove extra spaces from summary
|
summary = " ".join(summary.split()) # remove extra spaces from summary
|
||||||
summary = summary.split('/') # split summary and project into 2 strings
|
summary = summary.split('/') # split summary and project into 2 strings
|
||||||
project = summary[0] # store the project name from the summary into a variable
|
project = summary[0] # store the project name from the summary into a variable
|
||||||
print('Project: ' + project) # print project
|
print('Project: ' + project) # print project
|
||||||
else:
|
else:
|
||||||
print(
|
print('\n' + myUser + ' not found for project ' + myProject + '.\n') # notify if user not found
|
||||||
'\nSearching project id ' + dnet_project_id + '...\n'
|
|
||||||
'\n' + dnet_search_text + ' not found.\n') # notify if user not found
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
line = 0
|
line = 0
|
||||||
for match in soup.find_all('td',align='right'): # search soup for table data
|
for match in soup.find_all('td',align='right'): # search soup for table data
|
||||||
line +=1
|
line +=1
|
||||||
if line == 1: # print overall rank
|
if line == 1: # print overall rank
|
||||||
overall_rank = match.text.lstrip()
|
overallRank = match.text.lstrip()
|
||||||
if overall_rank[0] != "T" and overall_rank[0] != "0":
|
if overallRank[0] != "T" and overallRank[0] != "0":
|
||||||
overall_rank = overall_rank.split('(')
|
overallRank = overallRank.split('(')
|
||||||
overall_rank = overall_rank[0]
|
overallRank = overallRank[0]
|
||||||
if line == 2: # print current rank
|
if line == 2: # print current rank
|
||||||
current_rank = match.text.lstrip()
|
currentRank = match.text.lstrip()
|
||||||
if current_rank[0] != "0":
|
if currentRank[0] != "0":
|
||||||
current_rank = current_rank.split('(')
|
currentRank = currentRank.split('(')
|
||||||
current_rank = current_rank[0]
|
currentRank = currentRank[0]
|
||||||
if line == 3: # stop searching soup
|
if line == 3: # stop searching soup
|
||||||
print ('Current Rank: ' + current_rank)
|
print ('Current Rank: ' + currentRank)
|
||||||
print ('Overall Rank: ' + overall_rank + '\n')
|
print ('Overall Rank: ' + overallRank + '\n')
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print('An error has occured.')
|
print('An error has occured.')
|
||||||
Reference in new issue
Block a user