Beispiel #1
0
Datei: ajax.py Projekt: mpresh/rf
def tweet_wrapper(req, campaign_id=""):
    user = User.objects.get(id=req.session["user_id"])	

    msg=req.GET["message"]
    if len(msg) > 115:
        msg = msg[:115]

    if "shash" in req.GET:
        parent_shash = req.GET["shash"]
    elif "shash" in req.POST:
        parent_shash = req.POST["shash"]
    else:
        parent_shash = None

    if "parent_url" in req.GET:
        parent_url = req.GET["parent_url"]
        parent_url = urllib.unquote(parent_url)
        parent_url = parent_url.replace("#", "")
        parsed_url = urlparse.urlparse(parent_url)
        try:
            list_vals = parsed_url.query.split("&")
        except Exception:
            list_vals = parsed_url[4]
        print "parsed_url", parsed_url
        print "list vals", list_vals
        dict = {}
        for val in list_vals:
            if val:
                k, v = val.split("=")
                dict[k] = v
        if "shash" in dict:
            parent_shash = dict["shash"][0]
    else:
        parent_url = None

    share = Share(message=msg,
                  campaign=Campaign.objects.get(id=campaign_id),
                  from_user_facebook=None,
                  from_user_twitter=user,
                  from_account_type="T",
                  parent_shash=parent_shash,
                  reach=user.get_num_follower_list()
                  )

    share.save()
    user.tweet(msg)

    share.setHash()
    url = share.url(req, parent=parent_url)
    short_url = bitly.shorten(url)
    share.url_short = short_url
    msg = msg + " " + short_url

    share.save()

    dict = {}
    dict["status"] = "ok!"
    dict["url"] = short_url
    dict["msg"] = msg
    return (dict)
Beispiel #2
0
Datei: ajax.py Projekt: mpresh/rf
def campaign_facebook_update(req, campaign_id=""):
    """ Send feed update to facebook from user share. """

    fbuser = FBUser.objects.get(facebook_id=req.session["uid"])

    msg = req.GET["message"]
    if len(msg) > 125:
        msg = msg[:125]

    if "shash" in req.GET:
        parent_shash = req.GET["shash"]
    else:
        parent_shash = None

    if "parent_url" in req.GET:
        parent_url = req.GET["parent_url"]
        parent_url = urllib.unquote(parent_url)
        parent_url = parent_url.replace("#", "")
        parsed_url = urlparse.urlparse(parent_url)
        try:
            list_vals = parsed_url.query.split("&")
        except Exception:
            list_vals = parsed_url[3]
        dict = {}
        for val in list_vals:
            if val:
                k, v = val.split("=")
                dict[k] = v
        if "shash" in dict:
            parent_shash = dict["shash"][0]
    else:
        parent_url = None

    c = Campaign.objects.get(id=campaign_id)

    share = Share(
        message=msg,
        campaign=c,
        from_user_facebook=fbuser,
        from_user_twitter=None,
        from_account_type="F",
        parent_shash=parent_shash,
        reach=fbuser.num_friends(),
    )

    share.save()
    share.setHash()
    url = share.url(req, parent=parent_url)
    short_url = bitly.shorten(url)
    share.url_short = short_url
    msg = msg + " " + short_url

    share.save()
    fbuser.feed(message=msg)
    fbuser.campaign_interested.add(c.id)
    dict = {}
    dict["status"] = "ok!"
    dict["url"] = short_url
    dict["msg"] = msg
    return HttpResponse(json.dumps(dict))
Beispiel #3
0
Datei: ajax.py Projekt: mpresh/rf
def event_tweet_invite(req, event_id=""):
    """ Tweet out invite to everyone. """
    ret_obj = {}

    if "user_id" not in req.session:
        ret_obj["status"] = "error"
        ret_obj["message"] = "User Must be Logged in."
        return HttpResponse(json.dumps(ret_obj))

    user = User.objects.get(id=req.session["user_id"])	

    msg=req.GET["message"]
    if len(msg) > 125:
        msg = msg[:125]

    if "shash" in req.GET:
        parent_shash = req.GET["shash"]
    elif "shash" in req.POST:
        parent_shash = req.POST["shash"]
    else:
        parent_shash = None

    share = Share(message=msg,
                  event=Event.objects.get(id=event_id),
                  from_user_facebook=None,
                  from_user_twitter=user,
                  from_account_type="T",
                  parent_shash=parent_shash,
                  reach=user.get_num_follower_list()
                  )
    share.save()

    share.setHash()

    url = share.url(req)
    short_url = bitly.shorten(url)

    share.url_short = short_url
    msg = msg + " " + short_url

    share.save()
    user.tweet(msg)

    dict = {}
    dict["status"] = "ok!"
    dict["url"] = short_url
    dict["msg"] = msg
    return HttpResponse(json.dumps(dict))