forked from phonedude/cs532-s17
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetFeed.py
58 lines (47 loc) · 1.34 KB
/
getFeed.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
from bs4 import BeautifulSoup
import os
def getFeed(filename):
print("FILENAME:", filename)
with open("data/blogs/" + filename) as f:
f.seek(0)
html = f.read()
soup = BeautifulSoup(html, 'html.parser')
feed = soup.find_all(
'link', attrs={'type': 'application/atom+xml'})
if(feed):
return feed[0]['href']
return None
def deleteNoFeedFiles():
noneLines = []
f = open("data/feedList.txt", "r+")
d = f.readlines()
f.seek(0)
for i, line in enumerate(d):
if 'None' in line:
noneLines.append(i)
else:
f.write(line)
f.truncate()
f.close()
print(noneLines)
f = open("data/blogList.txt", "r+")
d = f.readlines()
f.seek(0)
for i, line in enumerate(d):
if i in noneLines:
# delete file
fileToDelete = line.split(' ')[0]
print("Deleting:", fileToDelete)
os.remove("data/blogs/" + fileToDelete)
else:
f.write(line)
f.truncate()
f.close()
if __name__ == "__main__":
with open("data/blogList.txt") as f, open("data/feedList.txt", 'w') as out:
for line in f:
filename = line.split(' ')[0]
feed = getFeed(filename)
print(feed, file=out)
deleteNoFeedFiles()