-
Notifications
You must be signed in to change notification settings - Fork 4
/
createcontent.py
executable file
·48 lines (39 loc) · 1.21 KB
/
createcontent.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
#!/usr/bin/env python
import os
import requests
import re
import argparse
from datetime import datetime
# Set up arguments
parser = argparse.ArgumentParser(description='Grabs the pattern info from Subtle Patterns.')
parser.add_argument('-i','--input', help='Input site.', required=True)
args = vars(parser.parse_args())
original = args['input']
content = requests.get(original).content
title = re.findall('<h2>(.*)</h2>', content)[0].title()
date = datetime.now().strftime("%Y-%m-%d %H:%I:%S")
imgur = ""
slug = title.lower().replace(' ','-')
try:
authorsite, author = re.findall('Made by.+?<a href="(.+?)".*>(.*)</a>',content)[0]
except IndexError:
author = re.findall('Made by (.+?)\.',content)[0]
authorsite = ''
print title
print slug
print author
print authorsite
print original+"\n"
filename = './content/' + slug + '.md'
if os.path.isfile(filename):
print "Error: file exists."
exit()
writefile = open(filename,'w')
writefile.write("title: %s\n" % title)
writefile.write("date: %s\n" % date)
writefile.write("imgur: %s\n" % imgur)
writefile.write("slug: %s\n" % slug)
writefile.write("author: %s\n" % author)
writefile.write("authorsite: %s\n" % authorsite)
writefile.write("original: %s\n" % original)
writefile.close()