Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: retweet #465

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hasjob/models/jobpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class JobPost(BaseMixin, db.Model):
review_datetime = db.Column(db.DateTime, nullable=True)
review_comments = db.Column(db.Unicode(250), nullable=True)

# Social media links
tweetid = db.Column(db.Unicode(30), nullable=True)

search_vector = deferred(db.Column(TSVECTOR, nullable=True))

_state = db.Column('status', db.Integer, StateManager.check_constraint('status', POST_STATE),
Expand Down
12 changes: 9 additions & 3 deletions hasjob/templates/detail.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,15 @@
<a class="list-group-item visible-xs-block visible-sm-block" href="whatsapp://send?text={{ headline|urlquoteplus }}+{{ post.url_for(utm_campaign='share', utm_medium='whatsapp', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-whatsapp"></i>&nbsp;&nbsp; Share on WhatsApp
</a>
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/share?url={{ post.url_for(utm_campaign='share', utm_medium='twitter', _external=true)|urlquoteplus }}&amp;counturl={{ post.url_for(_external=true)|urlquoteplus }}&amp;via=hasjob&amp;related=hasjob:HasGeek%20Job%20Board&amp;text=Job%3A%20{{ headline|urlquoteplus }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Tweet this
</a>
{%- if post.tweetid %}
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/intent/retweet?tweet_id={{ post.tweetid }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Retweet this
</a>
{%- else%}
<a class="list-group-item share-popup" data-width="550" data-height="250" rel="noopener" target="_blank" href="https://twitter.com/share?url={{ post.url_for(utm_campaign='share', utm_medium='twitter', _external=true)|urlquoteplus }}&amp;counturl={{ post.url_for(_external=true)|urlquoteplus }}&amp;via=hasjob&amp;related=hasjob:HasGeek%20Job%20Board&amp;text=Job%3A%20{{ headline|urlquoteplus }}">
<span class="badge" id="tweet-count"></span><i class="fa fa-fw fa-twitter"></i>&nbsp;&nbsp; Tweet this
</a>
{%- endif %}
<a class="list-group-item share-popup" data-width="520" data-height="230" rel="noopener" target="_blank" href="http://www.facebook.com/sharer.php?s=100&p[url]={{ post.url_for(utm_campaign='share', utm_medium='facebook', _external=true)|urlquoteplus }}">
<i class="fa fa-fw fa-facebook"></i>&nbsp;&nbsp; Share on Facebook
</a>
Expand Down
19 changes: 18 additions & 1 deletion hasjob/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,25 @@
import json
import re
from hasjob import app
from hasjob.models import JobPost
from hasjob.models import db


@job('hasjob')
def tweet_post(post_id):
print "in tweet post"
post = JobPost.query.get(post_id)
if post.headlineb:
post.tweetid = tweet(post.headline, post.url_for(b=0, _external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
tweet(post.headlineb, post.url_for(b=1, _external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
else:
post.tweetid = tweet(post.headline, post.url_for(_external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
db.session.commit()


def tweet(title, url, location=None, parsed_location=None, username=None):
auth = OAuthHandler(app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(app.config['TWITTER_ACCESS_KEY'], app.config['TWITTER_ACCESS_SECRET'])
Expand Down Expand Up @@ -44,7 +60,8 @@ def tweet(title, url, location=None, parsed_location=None, username=None):
text = text + ' ' + locationtag
if username:
text = text + ' @' + username
api.update_status(text)
tweet_status = api.update_status(text)
return tweet_status.id


def shorten(url):
Expand Down
11 changes: 2 additions & 9 deletions hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
PAY_TYPE, ReportCode, UserJobView,
AnonJobView, JobApplication, Campaign, CAMPAIGN_POSITION, unique_hash,
viewstats_by_id_hour, viewstats_by_id_day)
from hasjob.twitter import tweet
from hasjob.twitter import tweet_post
from hasjob.tagging import tag_locations, add_to_boards, tag_jobpost
from hasjob.uploads import uploaded_logos
from hasjob.utils import get_word_bag, redactemail, random_long_key, common_legal_names
Expand Down Expand Up @@ -748,14 +748,7 @@ def confirm_email(domain, hashid, key):
post.confirm()
db.session.commit()
if app.config['TWITTER_ENABLED']:
if post.headlineb:
tweet.delay(post.headline, post.url_for(b=0, _external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
tweet.delay(post.headlineb, post.url_for(b=1, _external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
else:
tweet.delay(post.headline, post.url_for(_external=True),
post.location, dict(post.parsed_location or {}), username=post.twitter)
tweet_post.delay(post.id)
add_to_boards.delay(post.id)
flash("Congratulations! Your job post has been published. As a bonus for being an employer on Hasjob, "
"you can now see how your post is performing relative to others. Look in the footer of any post.",
Expand Down
23 changes: 23 additions & 0 deletions migrations/versions/d8258df712fa_tweet_id_for_jobpost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Tweet id for JobPost

Revision ID: d8258df712fa
Revises: 625415764254
Create Date: 2018-07-12 18:22:20.245244

"""

# revision identifiers, used by Alembic.
revision = 'd8258df712fa'
down_revision = '625415764254'

from alembic import op
import sqlalchemy as sa



def upgrade():
op.add_column('jobpost', sa.Column('tweetid', sa.Unicode(length=30), nullable=True))


def downgrade():
op.drop_column('jobpost', 'tweetid')