~parinporecha/gtg/global_shortcut

« back to all changes in this revision

Viewing changes to GTG/backends/tweepy/utils.py

  • Committer: Izidor Matušov
  • Date: 2013-01-10 15:03:42 UTC
  • Revision ID: izidor.matusov@gmail.com-20130110150342-ajwnwmc2trh9ia2v
Removing broken twitter and tweepy services

I don't know anybody uses them. They are broken, and pretty artificial (more proof of the concept). We should focus our efforts on normal synchronization.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Tweepy
2
 
# Copyright 2010 Joshua Roesslein
3
 
# See LICENSE for details.
4
 
 
5
 
from datetime import datetime
6
 
import time
7
 
import htmlentitydefs
8
 
import re
9
 
import locale
10
 
 
11
 
 
12
 
def parse_datetime(string):
13
 
    # Set locale for date parsing
14
 
    locale.setlocale(locale.LC_TIME, 'C')
15
 
 
16
 
    # We must parse datetime this way to work in python 2.4
17
 
    date = datetime(*(time.strptime(string, '%a %b %d %H:%M:%S +0000 %Y')[0:6]))
18
 
 
19
 
    # Reset locale back to the default setting
20
 
    locale.setlocale(locale.LC_TIME, '')
21
 
    return date
22
 
 
23
 
 
24
 
def parse_html_value(html):
25
 
 
26
 
    return html[html.find('>')+1:html.rfind('<')]
27
 
 
28
 
 
29
 
def parse_a_href(atag):
30
 
 
31
 
    start = atag.find('"') + 1
32
 
    end = atag.find('"', start)
33
 
    return atag[start:end]
34
 
 
35
 
 
36
 
def parse_search_datetime(string):
37
 
    # Set locale for date parsing
38
 
    locale.setlocale(locale.LC_TIME, 'C')
39
 
 
40
 
    # We must parse datetime this way to work in python 2.4
41
 
    date = datetime(*(time.strptime(string, '%a, %d %b %Y %H:%M:%S +0000')[0:6]))
42
 
 
43
 
    # Reset locale back to the default setting
44
 
    locale.setlocale(locale.LC_TIME, '')
45
 
    return date
46
 
 
47
 
 
48
 
def unescape_html(text):
49
 
    """Created by Fredrik Lundh (http://effbot.org/zone/re-sub.htm#unescape-html)"""
50
 
    def fixup(m):
51
 
        text = m.group(0)
52
 
        if text[:2] == "&#":
53
 
            # character reference
54
 
            try:
55
 
                if text[:3] == "&#x":
56
 
                    return unichr(int(text[3:-1], 16))
57
 
                else:
58
 
                    return unichr(int(text[2:-1]))
59
 
            except ValueError:
60
 
                pass
61
 
        else:
62
 
            # named entity
63
 
            try:
64
 
                text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
65
 
            except KeyError:
66
 
                pass
67
 
        return text # leave as is
68
 
    return re.sub("&#?\w+;", fixup, text)
69
 
 
70
 
 
71
 
def convert_to_utf8_str(arg):
72
 
    # written by Michael Norton (http://docondev.blogspot.com/)
73
 
    if isinstance(arg, unicode):
74
 
        arg = arg.encode('utf-8')
75
 
    elif not isinstance(arg, str):
76
 
        arg = str(arg)
77
 
    return arg
78
 
 
79
 
 
80
 
 
81
 
def import_simplejson():
82
 
    try:
83
 
        import simplejson as json
84
 
    except ImportError:
85
 
        try:
86
 
            import json  # Python 2.6+
87
 
        except ImportError:
88
 
            try:
89
 
                from django.utils import simplejson as json  # Google App Engine
90
 
            except ImportError:
91
 
                raise ImportError, "Can't load a json library"
92
 
 
93
 
    return json
94
 
 
95
 
def list_to_csv(item_list):
96
 
    if item_list:
97
 
        return ','.join([str(i) for i in item_list])
98