import oauth2 as oauth
import json
from msgvis.settings.common import TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET, DEBUG
import re


def get_embedded_html(tweet_original_id):

    if DEBUG:
        fake = r'<blockquote class="twitter-tweet" data-cards="hidden" > <p lang="en" dir="ltr">Sunsets don&#39;t get much better than this one over <a href="https://twitter.com/GrandTetonNPS">@GrandTetonNPS</a>. <a href="https://twitter.com/hashtag/nature?src=hash">#nature</a> <a href="https://twitter.com/hashtag/sunset?src=hash">#sunset</a> <a href="http://t.co/YuKy2rcjyU">pic.twitter.com/YuKy2rcjyU</a></p>&mdash; US Dept of Interior (@Interior) <a href="https://twitter.com/Interior/status/463440424141459456">May 5, 2014</a></blockquote>'
        return fake


    # Create your consumer with the proper key/secret.

    consumer = oauth.Consumer(key=TWITTER_ACCESS_TOKEN, secret=TWITTER_ACCESS_TOKEN_SECRET)

    # Request token URL for Twitter.
    request_token_url = "https://api.twitter.com/1.1/statuses/oembed.json?url=https://twitter.com/x/status/" + str(tweet_original_id)

    # Create our client.
    client = oauth.Client(consumer)

    # The OAuth Client request works just like httplib2 for the most part.
    resp, content = client.request(request_token_url, "GET")

    content = json.loads(content)

    pattern = re.compile("<blockquote.*</blockquote>")
    #html = ""
    if content.get('html'):
        html = pattern.match(content['html']).group()
        #html = content.get('html')
    return html

    #return "<p></p>"



@@ -130,16 +130,26 @@
 port re%0A
+import os%0A
 %0A%0Adef ge
@@ -197,16 +197,82 @@
 if DEBUG
+ or os.environ%5B%22DJANGO_SETTINGS_MODULE%22%5D == %22msgvis.settings.test%22
 :%0A      

change testing mode detection