forked from StackExchange/stack-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
soundcloud.py
38 lines (30 loc) · 1.02 KB
/
soundcloud.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
import os, re, requests
rootdir = '_posts'
for subdir, dirs, files in os.walk(rootdir):
for file in files:
filename = os.path.join(subdir, file)
contents = ""
with open(filename, "r") as f:
contents = f.readlines()
# Get WordPress
slug = filename.replace("_posts/", "").replace(".markdown", "")
splits = slug.split("-")
year = splits[0]
month = splits[1]
end = "-".join(splits[3:])
wordpress_url = "http://blog.stackoverflow.com" + "/" + "/".join([year, month, end])
if re.search('podcast', wordpress_url):
print wordpress_url
response = requests.get(wordpress_url)
if response:
for line in response.content.split("\n"):
if re.search('<iframe|<object', line) and re.search("soundcloud", line):
contents.append('\n'+line)
f = open(filename, "w")
f.write("".join(contents))
f.close()
continue
contents.append(iframe)
f = open(filename, "w")
f.write("".join(contents))
f.close()