Skip to content

Instantly share code, notes, and snippets.

@orymate
Last active December 17, 2015 14:49
Show Gist options
  • Save orymate/5626899 to your computer and use it in GitHub Desktop.
Save orymate/5626899 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from __future__ import unicode_literals
import urllib
import BeautifulSoup
import sys
import string
import codecs
soup = BeautifulSoup.BeautifulSoup(urllib.urlopen(sys.argv[1]))
try:
author = soup.findAll(attrs={"name": "author"})[0].content.string
except:
author = "FIXME"
slug = sys.argv[1][7:20].translate(string.maketrans("", ""),
string.punctuation)
with codecs.open("mybib.bib", "a", "utf-8") as f:
f.write('''
@misc{%s,
author = {%s},
title = {%s},
howpublished = {\\url{%s}}
}''' % (slug, author, soup.title.string, sys.argv[1]))
print "\cite{%s}" % (slug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment