forked from kelu124/echommunity
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanalyse.py
More file actions
133 lines (114 loc) · 4.31 KB
/
analyse.py
File metadata and controls
133 lines (114 loc) · 4.31 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -------------------------
# (c) kelu124
# cc-by-sa/4.0/
# -------------------------
# Analyse the locally stored slack data
# -------------------------
import re
import subprocess
import os
from os import walk
import json
# List of keywords
Hardware = ["pcb","fpga","electronic","cpld","stm32","arduino","kicad","tgc","adc","hardware","transistor","kit", "boards","redpitaya","dsp","amplifier","quad","cortex","embedded","zynq","altera", "mcu", "xilinx","cortex","zynq"]
Software = ["android","java","code","python","script","merge","software",'app',"gpu", "machine learning","neural", "deep learning","opengl","scan conversion", "scanconversion","big data"]
Legal = ["patent", "agreement", "cla","licence","license","legal","copyright"]
Medical = ["doctor", "patient",'médecin',"medical","medecin","medicin","emergency","health", "healthcare","physician","diagnosis","diabet","pregnant","pregnancy","liver","prevalence", "blood","fetal","midwi","epidemio", "biolog","clinic"]
Design = ["design", "user","interface"]
Community = ["graph", "community", "communication", "event", "contribution", "contributor", "wiki","documentation","presentation","contributeur","gitbook","onboard","knowledge "]
def getChannelLogs(mypath):
# getChannelLogs("./logs/")
f = []
for (dirpath, dirnames, filenames) in walk(mypath):
f.extend(filenames)
good = [x for x in f if (("C" in x) and ".log" in x)]
break
return good
def GetUserList(list):
People = []
usernames = {}
with open("./logs/users.log") as users:
for user in users:
WhoIs = user.strip().split(";")
People.append(WhoIs[0])
usernames[WhoIs[0]] = WhoIs[1]
#print usernames
return People
def OpenLog(logfile):
f = open("./logs/"+logfile,'r')
text = f.read()
f.close()
return text
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
# Initiate user list
Users = GetUserList("users.log")
# Get logs
Files = getChannelLogs("./logs/")
MainJSON = {"id":"MainJSON"}
# Process each log
for ChannelID in Files:
Log = OpenLog(ChannelID)
ChannelID = ChannelID.split(".")[0]
ChannelData = {"channel_id":ChannelID}
ChannelUsers = []
ChannelUserMentions = []
ChannelUserReactions = []
ChannelUserInfos = []
for User in Users:
CountSoft = 0
CountHard = 0
CountLegal = 0
CountMedical = 0
CountDesign = 0
CountCommunity = 0
for line in Log.split("\n"):
if User in line.split(":")[0]:
for hard in Hardware:
CountHard += line.lower().count(hard)
for soft in Software:
CountSoft += line.lower().count(soft)
for legal in Legal:
CountLegal += line.lower().count(legal)
for medical in Medical:
CountMedical += line.lower().count(medical)
for design in Design:
CountDesign += line.lower().count(design)
for community in Community:
CountCommunity += line.lower().count(community)
if "(reactions: " in line:
reacted = find_between( line, "(reactions: ", ")" ).split(",")
for reac in reacted:
reactions = {'user_id': User, 'mentioned_user_id': reac.replace("@",""), "ts" : line.split(">")[0]}
ChannelUserReactions.append(reactions)
if "<@" in line:
m = re.findall ( '<@(.*?)>', line, re.DOTALL)
for mentions in m:
if not (User == mentions):
mentionsJSON = {'user_id': User, 'mentioned_user_id' : mentions.replace("@",""), "ts" : line.split(">")[0]}
ChannelUserMentions.append(mentionsJSON)
UserInfo = {User : {'posts': str(Log.count(User)), 'software': str(CountSoft), 'hardware': str(CountHard), 'legal': str(CountLegal), 'medical': str(CountMedical), 'design': str(CountDesign), 'community': str(CountCommunity)}}
if Log.count(User):
ChannelUsers.append(User)
ChannelUserInfos.append(UserInfo)
ChannelData["mentions"] = ChannelUserMentions
ChannelData["reactions"] = ChannelUserReactions
ChannelData["users_info"] = ChannelUserInfos
ChannelData["users"] = ChannelUsers
#dumping channel-wise json
json_data = json.dumps(ChannelData, sort_keys=True, indent=4)
f = open("logs/"+ChannelID.split(".")[0]+".json","w+")
f.write(json_data)
f.close()
# Dumping main json
#json_data = json.dumps(MainJSON, sort_keys=True, indent=4)
#f = open("logs/MainJSON.json","w+")
#f.write(json_data)
#f.close()