Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Created August 9, 2017 09:24
Show Gist options
  • Save EncodeTheCode/064f27c91884d082902101bea82cdeac to your computer and use it in GitHub Desktop.
Save EncodeTheCode/064f27c91884d082902101bea82cdeac to your computer and use it in GitHub Desktop.
import csv
with open("content.txt",encoding="utf8") as f:r=f.readlines();f.close();
class globall():
s='description'
t='content.txt'
def string_perform(t,s): # Locate string value on line number for perform action
if s is None:s=globall.s
if t is None:t=globall.t
s=s or globall.s
t=t or globall.t
with open(t,encoding="utf8") as f:
for n,l in enumerate(f,1):
if s in l:
return n
def into(s): # Locates string and turns it into line number
return int(string_perform(0,str(s)))
# def l(n):return r[n-1]
# def l(n):return int(string_perform(0,n))
def l(n):return n
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(str(l).split())
s=s.split()[0:][4:5]
s=str(s).replace("['alt=\"","")
s=s.replace("\"']","")
s=s.replace("']","")
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=" ".join(str(l).split())
s=s.split()[0:]
s=str(s).replace("', 'points)</span><span'","")
s=s.replace(" 'class=\"details', 'js-link', 'a-default","")
s=s.replace(',"\', \'data-url="/ranking/teams/2017/august/7/details',"")
s=s.replace(">Details</span><span","")
s=s.replace(" \'class=\"filler\"></","")
s=s.replace("\"\',","")
s="/".join(s.split("/")[:-1])
return strip_data_team_points(s)
def get_pos_team_rank_shift(l): # Get team points
s=str(l).strip().split()[2:3]
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('<div class="change neutral">','')
s=s.replace('<div class="change positive">','')
s=s.replace('<div class="change negative">','')
s=s.replace('<div class="header"><span class="position">','')
s=s.replace('</div>','')
s=strip_junk_data(s)
s=s.split(' <')[0]
return s
def strip_data_team_method2(d): # Strip data from team
s=str(d).replace('<div class="change neutral">','')
s=s.replace('<div class="change positive">','')
s=s.replace('<div class="change negative">','')
s=s.replace('<div class="header"><span class="position">','')
s=s.replace('</div>','')
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)
_x1=-1 # Common increments -2, -5, -32 (22,17,49)
_x2=1 # Common increments +2, +5, +63 (24,29,92)
_x3=-1 # Common increments +3 (95)
pos1=[
r[into('6137/sk')-_x2], #1
r[into('6665/astralis')-_x2], #2
r[into('6651/gambit')-_x2], #3
r[into('6667/faze')-_x2], #4
r[into('5995/g2')-_x2], #5
] # Top team positions in top 5 list.
pos2=[
r[into('6137/sk')-_x2], #1
r[into('6665/astralis')-_x2], #2
r[into('6651/gambit')-_x2], #3
r[into('6667/faze')-_x2], #4
r[into('5995/g2')-_x2], #5
r[into('5752/cloud9')-_x2], #6
r[into('7010/immortals')-_x2], #7
r[into('5378/virtuspro')-_x2], #8
r[into('7533/north')-_x2], #9
r[into('4991/fnatic')-_x2], #10
r[into('5973/liquid')-_x2], #11
r[into('7532/big')-_x2], #12
r[into('4411/nip')-_x2], #13
r[into('6615/optic')-_x2], #14
r[into('4608/natus-vincere')-_x2], #15
r[into('5991/envyus')-_x2], #16
r[into('4494/mousesports')-_x2], #17
r[into('5310/hellraisers')-_x2], #18
r[into('7175/heroic')-_x2], #19
r[into('5988/flipsid3')-_x2], #20
r[into('5395/penta')-_x2], #21
r[into('6211/renegades')-_x2], #22
r[into('5974/clg')+_x3], #23
r[into('5929/space-soldiers')+_x3], #24
r[into('7613/red-reserve')+_x3], #25
r[into('6094/vega-squadron')+_x3], #26
r[into('6010/chiefs')+_x3], #27
r[into('7557/misfits')+_x1], #28
r[into('5422/dignitas')+_x1], #29
r[into('6902/godsent')+_x1] #30
] # Top 30 teams position.
pos_team=[
r[into('6137/sk')-_x2], #1
r[into('6665/astralis')-_x2], #2
r[into('6651/gambit')-_x2], #3
r[into('6667/faze')-_x2], #4
r[into('5995/g2')-_x2], #5
r[into('5752/cloud9')-_x2], #6
r[into('7010/immortals')-_x2], #7
r[into('5378/virtuspro')-_x2], #8
r[into('7533/north')-_x2], #9
r[into('4991/fnatic')-_x2], #10
r[into('5973/liquid')-_x2], #11
r[into('7532/big')-_x2], #12
r[into('4411/nip')-_x2], #13
r[into('6615/optic')-_x2], #14
r[into('4608/natus-vincere')-_x2], #15
r[into('5991/envyus')-_x2], #16
r[into('4494/mousesports')-_x2], #17
r[into('5310/hellraisers')-_x2], #18
r[into('7175/heroic')-_x2], #19
r[into('5988/flipsid3')-_x2], #20
r[into('5395/penta')-_x2], #21
r[into('6211/renegades')-_x2], #22
r[into('5974/clg')+_x3], #23
r[into('5929/space-soldiers')+_x3], #24
r[into('7613/red-reserve')+_x3], #25
r[into('6094/vega-squadron')+_x3], #26
r[into('6010/chiefs')+_x3], #27
r[into('7557/misfits')+_x1], #28
r[into('5422/dignitas')+_x1], #29
r[into('6902/godsent')+_x1] #30
] # Top 30 teams. (1 for unknown values. [Line number 1])
pos_team_points=[
r[into('6137/sk')-_x2], #1
r[into('6665/astralis')-_x2], #2
r[into('6651/gambit')-_x2], #3
r[into('6667/faze')-_x2], #4
r[into('5995/g2')-_x2], #5
r[into('5752/cloud9')-_x2], #6
r[into('7010/immortals')-_x2], #7
r[into('5378/virtuspro')-_x2], #8
r[into('7533/north')-_x2], #9
r[into('4991/fnatic')-_x2], #10
r[into('5973/liquid')-_x2], #11
r[into('7532/big')-_x2], #12
r[into('4411/nip')-_x2], #13
r[into('6615/optic')-_x2], #14
r[into('4608/natus-vincere')-_x2], #15
r[into('5991/envyus')-_x2], #16
r[into('4494/mousesports')-_x2], #17
r[into('5310/hellraisers')-_x2], #18
r[into('7175/heroic')-_x2], #19
r[into('5988/flipsid3')-_x2], #20
r[into('5395/penta')-_x2], #21
r[into('6211/renegades')-_x2], #22
r[into('5974/clg')+_x3], #23
r[into('5929/space-soldiers')+_x3], #24
r[into('7613/red-reserve')+_x3], #25
r[into('6094/vega-squadron')+_x3], #26
r[into('6010/chiefs')+_x3], #27
r[into('7557/misfits')+_x1], #28
r[into('5422/dignitas')+_x1], #29
r[into('6902/godsent')+_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='',encoding="utf8") as q:
n=0;w=csv.writer(q)
for i in pos_team:
n=n+1
w.writerow([get_team(l(i)),n,get_pos_team_points(l(i)).replace(' ','')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment