-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprocess.py
executable file
·43 lines (35 loc) · 935 Bytes
/
process.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
#!/usr/bin/python
import re
import operator
import sys
data = set()
class Link:
def __init__(self, date, source, target, count):
self.date=date
self.source=source
self.target=target
self.count=count
with open('raw.txt') as fp:
for line in fp:
temp = re.split("\t", line.rstrip())
arr = []
for idx, val in enumerate(temp):
arr.append(val.replace(" ", ""))
link = Link(arr[0][:4], arr[1], arr[2], int(arr[3]))
data.add(link)
sys.stdout.write("date")
sys.stdout.write(",")
sys.stdout.write("source")
sys.stdout.write(",")
sys.stdout.write("target")
sys.stdout.write(",")
sys.stdout.write("count\n")
for link in data:
sys.stdout.write(str(link.date))
sys.stdout.write(",")
sys.stdout.write(link.source)
sys.stdout.write(",")
sys.stdout.write(link.target)
sys.stdout.write(",")
sys.stdout.write(str(link.count))
sys.stdout.write("\n")