-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbc3.py
More file actions
158 lines (119 loc) · 4.55 KB
/
Copy pathbc3.py
File metadata and controls
158 lines (119 loc) · 4.55 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -------------------------
# (c) kelu124
# cc-by-sa/4.0/
# -------------------------
from bs4 import BeautifulSoup
import re
import os
import urllib2
import datetime
import html2text
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
Messages = []
Noms = ["Mehdi","Kelu","Olivier","Emilie","Djalel","Benjamin","Muriel","Jerome","Jérôme","Jérome","Jerôme","Benoit","Vincent","Constant","Benoît","Pierre","Carlos","Farad","Laurel","Oliv","Luc"]
Family = ["Benchoufi","De Fresnoye","Mayer","Vincent","KHOYRATEE","de Fresnoye", "De fresnoye", "Jonveaux","Vincent","Dubois","Bourdeloux","LICCIONI"]
BigFile = ""
def Clean(txt):
CleanTxt = str(txt)
CleanTxt = html2text.html2text(CleanTxt)
CleanTxt = CleanTxt.replace("<br/>"," ")
CleanTxt = CleanTxt.replace("\n\n","$$$$$$")
CleanTxt = CleanTxt.replace("\n"," ")
CleanTxt = CleanTxt.replace("$$$$$$","\n\n")
CleanTxt = CleanTxt.replace(" "," ")
CleanTxt = CleanTxt.replace(" ]","]")
CleanTxt = CleanTxt.replace("[ ","[")
for nom in Noms:
CleanTxt = CleanTxt.replace(nom,"Hyacinthe")
CleanTxt = CleanTxt.replace(nom.lower(),"Hyacinthe")
for family in Family:
CleanTxt = CleanTxt.replace(family,"Lacenne")
CleanTxt = CleanTxt.replace(family.lower(),"lacenne")
CleanTxt = CleanTxt.replace("lacenne hyacinthe","Hyacinthe")
CleanTxt = CleanTxt.replace("hyacinthe lacenne","Hyacinthe")
CleanTxt = CleanTxt.replace("Hyacinthe VINCENT","Hyacinthe")
CleanTxt = CleanTxt.replace("Hyacinthe LACENNE","Hyacinthe")
CleanTxt = CleanTxt.replace("Hyacinthe Lacenne","Hyacinthe")
CleanTxt = CleanTxt.replace("lacenne Hyacinthe","Hyacinthe")
oldPath = "./../../echopen-155345/all%20files%20-%20images%20pdfs%20spreadsheets%20etc/"
newPath = "bc3-raw/files/"
CleanTxt = CleanTxt.replace(oldPath,newPath)
CleanTxt = CleanTxt.replace("{{","'")
CleanTxt = CleanTxt.replace("}}","'")
if GetDateBC3(CleanTxt)[0]:
CleanTxt = CleanTxt.replace(GetDateBC3(CleanTxt)[1],GetDateBC3(CleanTxt)[0])
#print "stripped!"
CleanTxt = CleanTxt.replace(",**","**")
CleanTxt = CleanTxt.replace("hyancinthe","Hyacinthe")
CleanTxt = CleanTxt.replace("Hyacinthe124","kelu124")
CleanTxt = CleanTxt.replace("(bc3-raw/files/","(../bc3-images/")
# Removing the stuff !\[\](*avatar*)
#([\w.-]+)@([\w.-]+)
match = re.search(r'!\[.*avatar.*\.png\)', CleanTxt)
if match:
print str(match.group())
CleanTxt = CleanTxt.replace(str(match.group()),"Hyacinthe")
return CleanTxt.strip()
def GetDateBC3(text):
match = re.search(r'[A-Za-z]{3} \d{2}, \d{4}', text)
#print match
if match:
rawdate = str(match.group())
date= str(datetime.datetime.strptime(match.group(), '%b %d, %Y').date())
else:
date = 0
rawdate = 0
return date,rawdate
for root, directories, filenames in os.walk('./'):
for filename in filenames:
#print os.path.join(root,filename)
if (".html" in filename) and ("bc3-raw" in root):
Messages.append(os.path.join(root,filename) )
for item in Messages:
MessageBC2 = ""
info = item.split("/")
print info
fileset = info[-2].split("-")[1]
#print fileset
filename = info[-1].split(".")[0].split("-")[-1]
print filename
SaveFile = filename+".md"
soup = BeautifulSoup(open(item), "lxml")
titre = soup.find_all('h1', {'class' : 'flush--top'})[0]
MessageBC2 += Clean(titre) +" "
DateAChopper = str(soup.find_all('small', {'class' : 'metadata'})[0])
TimeSTAMP = ""
if GetDateBC3(DateAChopper)[0]:
TimeSTAMP += " - "+ GetDateBC3(DateAChopper)[0]
else:
TimeSTAMP += " - "+ DateAChopper
MessageBC2 += TimeSTAMP+"\n\n"
Contenu = soup.find_all('div', {'class' : 'formatted_content'})
if len(Contenu):
MessageBC2 += Clean(Contenu[0]) +"\n\n"
Comments = soup.find_all('div', {'class' : 'thread__entries'})
if len(Comments):
realComment = Comments[0].find_all('article', {'class' : 'thread-entry'})
for comment in realComment:
if comment.find_all('strong', {'class' : 'thread-entry__author'}):
MessageBC2 += "### "+Clean(comment.find_all('strong', {'class' : 'thread-entry__author'})[0])
Date = Clean(comment.find_all('span', {'class' : 'thread-entry__metadata__time'})[0])
if GetDateBC3(Date)[0]:
MessageBC2 += " - "+ GetDateBC3(Date)[0]
else:
MessageBC2 += " - "+ Date
MessageBC2 += "\n\n"
MessageBC2 += Clean(comment.find_all('div', {'class' : 'formatted_content'})[0]) +"\n\n"
#print MessageBC2
file = open("./bc3-data/"+SaveFile, 'w')
file.write(MessageBC2)
file.close()
BigFile += "\n\n"+MessageBC2
file = open("./bc3-data/Readme.md", 'w')
file.write(BigFile)
file.close()
#html2text.html2text()