Beispiel #1
0
def tweet_joke(joke_id):
  if session['logged_in'] != True:
    abort(401)
  else:
    j = Joke.query.get(joke_id)
    if not j:
      abort(404)

    # Make temp file
    fn, attribution = _render_joke_to_file(j)

    if not j.published_at:
      #publish to tumblr first
      user_id = session['logged_in_user']
      u = User.query.get(user_id)
      if fn:
#        adapted = tumblr_imagepost(j, fn, attribution=attribution, url=url_for("display_joke", joke_id=j.id))
        adapted = tumblr_imagepost(j, fn, attribution=attribution)
        if adapted:
          adapted.published_by_id = u.id
          db_session.add(adapted)
          db_session.add(u)
          db_session.commit()
          flash("Published to {0}/{1}".format(blog, j.tumblr_id))
    
    tumblr_id = j.tumblr_id
    tweet_text, resp = twitter_imagepost(j, fn, tumblr_id = tumblr_id)
    if resp:
      flash(u"Successfully tweeted -> <a href=\"https://twitter.com/VictorianHumour/status/{1}\">'{0}'</a>".format(tweet_text, str(resp['id'])))
      j.twitter_id = resp['id']
      db_session.add(j)
      db_session.commit()
    return redirect(url_for('display_joke', joke_id=j.id))
Beispiel #2
0
def publish_to_tumblr(joke_id):
  if session['logged_in'] != True:
    abort(401)
  else:
    j = Joke.query.get(joke_id)
    if not j:
      abort(404)
    if not j.published_at:
      user_id = session['logged_in_user']
      u = User.query.get(user_id)
      fn, attribution = _render_joke_to_file(j)
      if fn:
        adapted = tumblr_imagepost(j, fn, attribution=attribution, url=url_for("display_joke", joke_id=j.id))
        if adapted:
          adapted.published_by_id = u.id
          db_session.add(adapted)
          db_session.add(u)
          db_session.commit()
          flash("Published to {0}/{1}".format(blog, j.tumblr_id))
          # Delete file?
          return redirect(url_for('display_joke', joke_id=j.id))
    else:
      flash("Already published")
      return redirect(url_for('display_joke', joke_id=j.id))