Skip to content

Commit

Permalink
fix bug with pickle
Browse files Browse the repository at this point in the history
  • Loading branch information
Guitlle committed Apr 9, 2021
1 parent c8f1315 commit 400ac11
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
31 changes: 21 additions & 10 deletions automatizacion/autovoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import pickle
import datetime

# Attempt to load state from pickle file
try:
with open("state.pickle", "rb") as f:
state = pickle.load(f)
except:
print("Init state")
state = {"votos": [], "last_called": datetime.datetime.now()}

# The votes made by this script:
votos = state["votos"]

# Do not continue if a vote has been made in the last 30 minutes ( to avoid using all voting power)
if len(votos) > 0:
print("Último voto: ", votos[-1])
print("Tiempo: ", datetime.datetime.now());
Expand All @@ -25,32 +29,39 @@

_2days = datetime.timedelta(days=2)
_5mins = datetime.timedelta(minutes=2)
dryrun = False
dryrun = True
account = os.getenv("hiveaccount")
user = Account(account)
pkey = os.getenv("postingkey")

# Read the accounts to vote on
with open("cuentas", "r") as f:
cuentas = [s.strip() for s in f.readlines()]



# Init hive
hive = Hive(keys=[pkey])
weight = 100
votado = False

# For each account
for cuenta in cuentas:
print("Cuenta ", cuenta)
# q = Query(limit=2, tag=cuenta)
# Read the last discussion and vote if haven't already voted:
for h in discussions.Discussions_by_author_before_date(cuenta, limit=1):
print("Post https://hive.blog/@" + cuenta + "/" + h.permlink, h["created"])
print("Post https://hive.blog/@" + cuenta + "/" + h.permlink, " | ", h["created"], " | ", h.reward)
age = h.time_elapsed()

# Avoid curation reward penalty and voting on too old posts:
if age > _2days or age < _5mins:
print("Skipping")
continue
mivoto = h.get_vote_with_curation(account, raw_data=True)
if mivoto is None:

# If no vote was already made:
if mivoto is not None:
print("Votando")

# Make transaction and broadcast:
tx = TransactionBuilder(blockchain_instance=hive)
tx.appendOps(Vote(**{
"voter": account,
Expand All @@ -67,13 +78,13 @@
votado = True
votos.append({
"time": datetime.datetime.now(),
"permlink": h.permlink,
"rewards": h.get_rewards()
"permlink": h.permlink, "author": h.author,
"rewards": float(h.reward)
})
print(votos[-1])
if votado is True:
break


# Update and save script state
with open("state.pickle", "wb") as f:
state["votos"] = votos
state["last_called"] = datetime.datetime.now()
Expand Down
7 changes: 0 additions & 7 deletions automatizacion/cuentas

This file was deleted.

0 comments on commit 400ac11

Please sign in to comment.