-
Notifications
You must be signed in to change notification settings - Fork 6
/
mergeold.py
33 lines (28 loc) · 906 Bytes
/
mergeold.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
import re
import collections
import sys
#DO NOT USE ON DATA.TXT WITH EXISTING SITE RANK
#This tool is only for the initial appending of site rank.
#A separate tool will be developed to update site rank. Sit tight!
#Get site ranks
filename = 'peerlist.txt'
textfile = open(filename, 'r')
filetext = textfile.read()
textfile.close()
newsites = dict(item.split(" ") for item in filetext.split('\n'));
#Get existing sites
filename = 'data.txt'
textfile = open(filename, 'r')
data = textfile.read().split('\r')
textfile.close()
#Append rank to existing sites and store to a new data file
f = open("datanew.txt","w")
for line in data:
siteaddress = line.split(":")[1].strip()
f.write(line+" "+newsites.pop(siteaddress, '-'))
f.close()
#Store new sites in a separate file for tagging
f = open("newsites.txt","w")
for site in newsites:
f.write("New Site[:"+site+" "+newsites.get(site,'-')+"\n\r")
f.close()