Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Last active March 3, 2017 01:38
Show Gist options
  • Save EncodeTheCode/b385c8eee74de9b952b5ac15c5135a32 to your computer and use it in GitHub Desktop.
Save EncodeTheCode/b385c8eee74de9b952b5ac15c5135a32 to your computer and use it in GitHub Desktop.
# HLTV stats reader written by ETC (EncodeTheCode)
import csv
with open("content.txt") as f:r=f.readlines();f.close();
def l(n):return r[n-1]
def get_pos_team1(l): # Get team position in top 5 list
s=l.strip().split()[3:]
return strip_data_pos(s)
def get_pos_team2(l): # Get team position
return strip_data_team_pos(l)
def get_team(l): # Get team name
# s=l.strip().split()[4:5]
# s=l.split()[4:5]
s=" ".join(l.split())
return strip_data_team(s)
#def get_pos_team_points(l): # Get team points
# s=l.strip().split()[6:7]
# return strip_data_team_points(s)
def get_pos_team_points(l): # Get team points
s=l.strip().split()[6:8]
s=str(s).strip("=:>-<abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ\"'\' ()[]\'")
s=s.strip("\',")
return strip_data_team_points(s)
def strip_data_pos(d): # Strip data from position in top 5 list
s=str(d).strip("href=\"/ranking/teams/\"></a></div[]'")
return s.split('(')[-1]
def strip_data_team_pos(d): # Strip data from position
s=str(d).replace('<div class="ranking-number">','')
s=s.replace('</div>','').split(' <')[0].split()
s=str(s).strip("[]'")
return s
def strip_data_team(d): # Strip data from team
s=str(d).replace('<a style="" href="#" onclick="return false;">','')
s=s.replace('</a>','')
s=strip_junk_data(s)
s=s.split(' <')[0]
return s
def strip_data_team_points(d): # Strip data from team points
s=str(d).strip("=:>-<abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ\"'()[]\'")
return s.split('(')[-1]
def strip_junk_data(s):
b='<div class="boxBarText"><a href="/?pageid=15"><img src="http://static.hltv.org//images/txt_activethreads.gif" alt="" /></div>'
return s.replace(b,"",1)
pos1=[
871,
880,
889,
898,
907
] # Top team positions in top 5 list.
pos2=[
1143,
1284,
1425,
1566,
1707,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] # Top 30 teams position.
_x1=49 # Common increments -2, -5, -32 (22,17,49)
_x2=92 # Common increments +2, +5, +63 (24,29,92)
_x3=95 # Common increments +3 (95)
pos_team=[
1147-_x2, #1
1288-_x2, #2
1429-_x2, #3
1570-_x2, #4
1711-_x2, #5
1852-_x2, #6
1993-_x2, #7
2134-_x2, #8
2275-_x2, #9
2416-_x2, #10
2557-_x2, #11
2698-_x2, #12
2839-_x2, #13
2980-_x2, #14
3121-_x2, #15
3262-_x2, #16
3403-_x2, #17
3544-_x2, #18
3685-_x2, #19
3826-_x2, #20
3967-_x2, #21
4108-_x2, #22
4203+_x3, #23
4344+_x3, #24
4485+_x3, #25
4626+_x3, #26
4767+_x3, #27
4908+_x1, #28
5049+_x1, #29
5190+_x1 #30
] # Top 30 teams. (1 for unknown values. [Line number 1])
pos_team_points=[
1147-_x2, #1
1288-_x2, #2
1429-_x2, #3
1570-_x2, #4
1711-_x2, #5
1852-_x2, #6
1993-_x2, #7
2134-_x2, #8
2275-_x2, #9
2416-_x2, #10
2557-_x2, #11
2698-_x2, #12
2839-_x2, #13
2980-_x2, #14
3121-_x2, #15
3262-_x2, #16
3403-_x2, #17
3544-_x2, #18
3685-_x2, #19
3826-_x2, #20
3967-_x2, #21
4108-_x2, #22
4203+_x3, #23
4344+_x3, #24
4485+_x3, #25
4626+_x3, #26
4767+_x3, #27
4908+_x1, #28
5049+_x1, #29
5190+_x1 #30
] # Top 5 teams points.
# 871 # 1th
# 880 # 2nd
# 889 # 3rd
# 898 # 4th
# 907 # 5th
for i in pos2:print(get_pos_team2(l(i)))
# 1147 # SK
# 1288 # Virtus.pro
# 1429 # G2
# 1570 # NiP
# 1711 # Cloud9
for i in pos_team:print(get_team(l(i)))
# 1147 # 839
# 1288 # 711
# 1429 # 578
# 1570 # 524
# 1711 # 501
for i in pos_team_points:print(get_pos_team_points(l(i)))
# CSV writes
#with open('toplist.csv','w',newline='') as q:
# w=csv.writer(q)
# for i in pos_team:
# w.writerow([get_team(l(i))])
#with open('toplist.csv','w',newline='') as q:
# w=csv.writer(q)
# for m in pos2:
# for i in pos_team:
# w.writerow([get_team(l(i)),get_pos_team2(l(m))])
#with open('toplist.csv','w',newline='') as q:
# w=csv.writer(q)
# for i in pos_team:
# w.writerow([get_team(l(i)),int(i)])
with open('toplist.csv','w',newline='') as q:
n=0;w=csv.writer(q)
for i in pos_team:
n=n+1
w.writerow([get_team(l(i)),n-1,get_pos_team_points(l(i))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment