mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-21 05:44:54 +00:00
60 lines
1.3 KiB
Python
Executable file
60 lines
1.3 KiB
Python
Executable file
# Tweepy
|
|
# Copyright 2010 Joshua Roesslein
|
|
# See LICENSE for details.
|
|
|
|
from datetime import datetime
|
|
import time
|
|
import htmlentitydefs
|
|
import re
|
|
import locale
|
|
from urllib import quote
|
|
from email.utils import parsedate
|
|
|
|
|
|
def parse_datetime(string):
|
|
return datetime(*(parsedate(string)[:6]))
|
|
|
|
|
|
def parse_html_value(html):
|
|
|
|
return html[html.find('>')+1:html.rfind('<')]
|
|
|
|
|
|
def parse_a_href(atag):
|
|
|
|
start = atag.find('"') + 1
|
|
end = atag.find('"', start)
|
|
return atag[start:end]
|
|
|
|
|
|
def convert_to_utf8_str(arg):
|
|
# written by Michael Norton (http://docondev.blogspot.com/)
|
|
if isinstance(arg, unicode):
|
|
arg = arg.encode('utf-8')
|
|
elif not isinstance(arg, str):
|
|
arg = str(arg)
|
|
return arg
|
|
|
|
|
|
|
|
def import_simplejson():
|
|
try:
|
|
import simplejson as json
|
|
except ImportError:
|
|
try:
|
|
import json # Python 2.6+
|
|
except ImportError:
|
|
try:
|
|
from django.utils import simplejson as json # Google App Engine
|
|
except ImportError:
|
|
raise ImportError, "Can't load a json library"
|
|
|
|
return json
|
|
|
|
def list_to_csv(item_list):
|
|
if item_list:
|
|
return ','.join([str(i) for i in item_list])
|
|
|
|
def urlencode_noplus(query):
|
|
return '&'.join(['%s=%s' % (quote(str(k), ''), quote(str(v), '')) \
|
|
for k, v in query.iteritems()])
|