-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrapeFeatured.py
executable file
·53 lines (39 loc) · 1.73 KB
/
scrapeFeatured.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
#!/usr/bin/env python3
"""Takes a CSV file as input and looks for new files in the database to add.
Then if there's any new files to add, it will add them to the database.
Copyright (C) 2015 Joshua Gordon <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License version 2 can be obtained at
http://www.gnu.org/licenses/gpl-2.0.html or by writing to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
import csv
import addEpisode
import sys
import urllib.parse
URL_PREFIX = "http://archive.spepmedia.com"
filemap = {"music": "music.ini", "sermon": "sermons.ini"}
writermap = dict()
for key, value in filemap.items():
writermap[key] = addEpisode.EpisodeWriter(value)
def parseAndAdd(csvfile):
with open(csvfile) as csvfile:
rows = csv.reader(csvfile)
for row in reversed(list(rows)):
if row[4] in filemap:
if not checkExistence(URL_PREFIX + urllib.parse.quote(row[1]), row[4]):
print(row[1] + " is new")
writermap[row[4]].writeEpisode(URL_PREFIX + urllib.parse.quote(row[1]))
def checkExistence(url, contentType):
return writermap[contentType].checkExistence(url)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage {} /path/to/featured.csv".format(sys.argv[0]))
sys.exit(1)
parseAndAdd(sys.argv[1])