Skip to content

Commit

Permalink
Merge 1ae050e into abb924c
Browse files Browse the repository at this point in the history
  • Loading branch information
SmokinCaterpillar committed Mar 28, 2018
2 parents abb924c + 1ae050e commit fff7197
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* SQLite is now used to store blockchain data
* New Poster class to allow for waiting
* New posting of trending without bots

*0.6.1a* - 2018-03-22

Expand Down
51 changes: 39 additions & 12 deletions integration_tests/bchain/postdata_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
from trufflepig.bchain.poster import Poster


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_test_top10post(steem):

steem.wallet.unlock(config.PASSWORD)
if config.PASSWORD:
steem.wallet.unlock(config.PASSWORD)

poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.1)
waiting_time=0.1,
no_posting_key_mode=config.PASSWORD is None)

posts = random_data.create_n_random_posts(10)
df = pd.DataFrame(posts)
Expand All @@ -35,14 +36,15 @@ def test_test_top10post(steem):
tbpd.comment_on_own_top_list(df, poster, permalink)


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_test_all_top_with_real_data(steem):

steem.wallet.unlock(config.PASSWORD)
if config.PASSWORD:
steem.wallet.unlock(config.PASSWORD)

poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.1)
waiting_time=0.1,
no_posting_key_mode=config.PASSWORD is None)

df = tpbg.scrape_hour_data(steem, stop_after=10)

Expand All @@ -62,14 +64,15 @@ def test_test_all_top_with_real_data(steem):
overview_permalink='jjj')


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_test_top20_vote_and_comment(steem):

steem.wallet.unlock(config.PASSWORD)
if config.PASSWORD:
steem.wallet.unlock(config.PASSWORD)

poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.1)
waiting_time=0.1,
no_posting_key_mode=config.PASSWORD is None)

posts = random_data.create_n_random_posts(10)
df = pd.DataFrame(posts)
Expand All @@ -78,12 +81,36 @@ def test_test_top20_vote_and_comment(steem):

df = tppp.preprocess(df, ncores=1)

account = config.ACCOUNT

tbpd.vote_and_comment_on_topK(df, poster, 'laida',
overview_permalink='lll')


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_create_wallet(steem):
tbpd.create_wallet(steem, config.PASSWORD, config.POSTING_KEY)
tbpd.create_wallet(steem, config.PASSWORD, config.POSTING_KEY)


def test_test_top_trending_post(steem):

if config.PASSWORD:
steem.wallet.unlock(config.PASSWORD)

poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.1,
no_posting_key_mode=config.PASSWORD is None)

posts = random_data.create_n_random_posts(10)
df = pd.DataFrame(posts)
df['reward'] = df.reward
df['predicted_votes'] = df.votes

df = tppp.preprocess(df, ncores=1)

date = pd.datetime.utcnow().date()

tbpd.post_top_trending_list(df, poster, date,
overview_permalink='iii',
trufflepicks_permalink='kkk',
steem_amount=10,
sbd_amount=10)
4 changes: 2 additions & 2 deletions integration_tests/bchain/postweeklyupdate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def test_existence(steem):
assert isinstance(result, str)


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_weekly_post(steem):
posts = create_n_random_posts(300)

Expand All @@ -72,7 +71,8 @@ def test_weekly_post(steem):
post_frame['sbd_bought_reward'] = 0
post_frame['bought_votes'] = 0

poster = Poster(account=config.ACCOUNT, steem=steem)
poster = Poster(account=config.ACCOUNT, steem=steem,
no_posting_key_mode=config.PASSWORD is None)
permalink = tppw.post_weakly_update(pipeline, post_frame,
poster=poster,
current_datetime=current_date)
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/pigonduty_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@
from trufflepig.bchain.poster import Poster


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_call_a_pig(steem):
current_datetime = '2018-03-03-18:21:30'

pipeline = MockPipeline()
poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.1)
waiting_time=0.1,
no_posting_key_mode=config.PASSWORD is None)

tppd.call_a_pig(poster=poster,
pipeline=pipeline, topN_permalink='www.test.com',
current_datetime=current_datetime, hours=0.1,
overview_permalink='dsfd')


@pytest.mark.skipif(config.PASSWORD is None, reason="needs posting key")
def test_call_a_pig_empty_frame(steem):
aacs = (('smcaterpillar','question-is-there-an-api-to-upload-images-to-steemit'),)

poster = Poster(steem=steem,
account=config.ACCOUNT,
waiting_time=0.51)
waiting_time=0.51,
no_posting_key_mode=config.PASSWORD is None)

pipeline = MockPipeline()
tppd.execute_call(comment_authors_and_permalinks=aacs,
Expand Down
40 changes: 40 additions & 0 deletions integration_tests/trending0bot_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import pytest

import pandas as pd
import trufflepig.bchain.getdata as tpgd
import trufflepig.preprocessing as tppp
import trufflepig.bchain.getaccountdata as tpad
from trufflepig.bchain.poster import Poster
import trufflepig.trending0bidbots as tt0b
from trufflepig.testutils.pytest_fixtures import steem
from trufflepig import config


def test_create_trending_post(steem):

current_datetime = pd.datetime.utcnow()

data_frame = tpgd.scrape_hour_data(steem=steem,
current_datetime=current_datetime,
ncores=32,
offset_hours=8,
hours=1, stop_after=20)


min_datetime = data_frame.created.min()
max_datetime = data_frame.created.max() + pd.Timedelta(days=8)
upvote_payments = tpad.get_upvote_payments_to_bots(steem=steem,
min_datetime=min_datetime,
max_datetime=max_datetime,
bots=['booster'])

data_frame = df = tppp.preprocess(data_frame, ncores=1)

data_frame = tppp.compute_bidbot_correction(post_frame=data_frame,
upvote_payments=upvote_payments)
account = config.ACCOUNT
poster = Poster(account=account, steem=steem,
no_posting_key_mode=config.PASSWORD is None)

tt0b.create_trending_post(data_frame, upvote_payments, poster, 'test',
'test', current_datetime)
22 changes: 22 additions & 0 deletions tests/bchain/posts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,26 @@ def test_weekly_update():
topics=topics)

assert body
assert title


def test_top_trending_post():
posts = random_data.create_n_random_posts(10)
df = pd.DataFrame(posts)
df = tppp.preprocess(df, ncores=1)

date = pd.datetime.utcnow().date()
df.image_urls = df.body.apply(lambda x: tptf.get_image_urls(x))

title, post = tbpo.top_trending_post(topN_authors=df.author,
topN_permalinks=df.permalink,
topN_titles=df.title,
topN_filtered_bodies=df.filtered_body,
topN_image_urls=df.image_urls,
topN_rewards=df.reward, sbd_amount=10,
steem_amount=10,
title_date=date, trufflepicks_link='de.de.de',
truffle_link='www.de')

assert post
assert title
51 changes: 47 additions & 4 deletions trufflepig/bchain/postdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

PERMALINK_TEMPLATE = 'daily-truffle-picks-{date}'

TRENDING_PERMALINK_TEMPLATE = 'non-bot-trending-{date}'


def post_topN_list(sorted_post_frame, poster,
current_datetime, overview_permalink, N=10):
Expand All @@ -38,7 +40,7 @@ def post_topN_list(sorted_post_frame, poster,
df = sorted_post_frame.iloc[:N, :]

logger.info('Creating top {} post'.format(N))
df.first_image_url = df.body.apply(lambda x: tftf.get_image_urls(x))
first_image_urls = df.body.apply(lambda x: tftf.get_image_urls(x))

steem_per_mvests = Converter(poster.steem).steem_per_mvests()
truffle_link = 'https://steemit.com/steemit/@{}/{}'.format(poster.account,
Expand All @@ -48,7 +50,7 @@ def post_topN_list(sorted_post_frame, poster,
topN_permalinks=df.permalink,
topN_titles=df.title,
topN_filtered_bodies=df.filtered_body,
topN_image_urls=df.first_image_url,
topN_image_urls=first_image_urls,
topN_rewards=df.predicted_reward,
topN_votes=df.predicted_votes,
title_date=current_datetime,
Expand All @@ -57,8 +59,6 @@ def post_topN_list(sorted_post_frame, poster,

permalink = PERMALINK_TEMPLATE.format(date=current_datetime.strftime('%Y-%m-%d'))
logger.info('Posting top post with permalink: {}'.format(permalink))
logger.info(title)
logger.info(body)
poster.post(body=body,
permalink=permalink,
title=title,
Expand Down Expand Up @@ -149,6 +149,46 @@ def vote_and_comment_on_topK(sorted_post_frame, poster,
poster.steem.reconnect()


def post_top_trending_list(sorted_post_frame, poster,
current_datetime, trufflepicks_permalink,
overview_permalink, sbd_amount,
steem_amount, N=10):
""" Post the no bot trending toplist to the blockchain"""
df = sorted_post_frame.iloc[:N, :]

logger.info('Creating top {} post'.format(N))
first_image_urls = df.body.apply(lambda x: tftf.get_image_urls(x))

steem_per_mvests = Converter(poster.steem).steem_per_mvests()
truffle_link = 'https://steemit.com/steemit/@{}/{}'.format(poster.account,
overview_permalink)
trufflepicks_link = 'https://steemit.com/steemit/@{}/{}'.format(poster.account,
trufflepicks_permalink)

title, body = tfbp.top_trending_post(topN_authors=df.author,
topN_permalinks=df.permalink,
topN_titles=df.title,
topN_filtered_bodies=df.filtered_body,
topN_image_urls=first_image_urls,
topN_rewards=df.reward,
title_date=current_datetime,
truffle_link=truffle_link,
steem_per_mvests=steem_per_mvests,
trufflepicks_link=trufflepicks_link,
sbd_amount=sbd_amount,
steem_amount=steem_amount)

permalink = TRENDING_PERMALINK_TEMPLATE.format(date=current_datetime.strftime('%Y-%m-%d'))
logger.info('Posting top trending post with permalink: {}'.format(permalink))
poster.post(body=body,
permalink=permalink,
title=title,
tags=tfbp.TRENDING_TAGS,
self_vote=False)

return permalink


def create_wallet(steem, password, posting_key,
active_key=None):
""" Creates a new wallet
Expand Down Expand Up @@ -184,3 +224,6 @@ def create_wallet(steem, password, posting_key,
logger.info('Key already present')

logger.info('Wallet is ready')



19 changes: 15 additions & 4 deletions trufflepig/bchain/poster.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

class Poster(object):
"""A class to allow for posting and taking care of posting intervals"""
def __init__(self, steem, account, self_vote_limit=94, waiting_time=WAIT):
def __init__(self, steem, account, self_vote_limit=94, waiting_time=WAIT,
no_posting_key_mode=False):
self.no_posting_key_mode = no_posting_key_mode
self.waiting_time = waiting_time
self.last_post_time = time.time() - self.waiting_time
self.steem = steem
Expand All @@ -36,7 +38,10 @@ def post(self, body, title, permalink, tags, self_vote=False):
self_vote = self.check_if_self_vote()
self.time2last_post()
logger.info('Posting: `{}` (`{}`)\n{}'.format(title, permalink, body))
return error_retry(self.steem.commit.post, retries=10,
if self.no_posting_key_mode:
logger.warning('Test mode NOT TRYING TO POST')
else:
return error_retry(self.steem.commit.post, retries=10,
sleep_time=4, errors=Exception)(author=self.account,
title=title,
body=body,
Expand All @@ -55,7 +60,10 @@ def vote(self, author, permalink, weight):
identifier = '@{author}/{permalink}'.format(author=author,
permalink=permalink)
logger.info('Voting on {} with weight {}.'.format(identifier,weight))
error_retry(self.steem.commit.vote, retries=5,
if self.no_posting_key_mode:
logger.warning('Test mode NOT TRYING TO VOTE!')
else:
error_retry(self.steem.commit.vote, retries=5,
sleep_time=4)(identifier=identifier,
weight=weight,
account=self.account)
Expand All @@ -73,7 +81,10 @@ def reply(self, body, parent_author, parent_permalink, self_vote=False,

self.time2last_post()
logger.info('Replying to {} with\n{}'.format(identifier, body))
return error_retry(self.steem.commit.post, retries=10,
if self.no_posting_key_mode:
logger.warning('Test mode NOT TRYING TO REPLY')
else:
return error_retry(self.steem.commit.post, retries=10,
sleep_time=4, errors=Exception)("",
body,
json_metadata=None,
Expand Down

0 comments on commit fff7197

Please sign in to comment.