Created
August 28, 2018 17:00
-
-
Save thehesiod/0ffde6e56ea56aede919fe6068a73f89 to your computer and use it in GitHub Desktop.
google upvote client
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
from collections import defaultdict | |
from datetime import datetime, timedelta | |
import sys | |
import os | |
import logging | |
from google.cloud import datastore | |
from google.appengine.ext import ndb | |
from google.appengine.ext.ndb import model | |
from google.appengine.datastore import datastore_rpc | |
from upvote.gae.datastore.models import santa | |
from upvote.gae.lib.voting import api | |
from upvote.gae.datastore.models.base import Blockable | |
from upvote.gae.datastore.models import user as user_models | |
from upvote.gae.lib.voting import api as voting_api | |
from upvote.gae.shared.common import settings | |
from upvote.shared import constants | |
def main(service_account_json): | |
config = ndb.ContextOptions(use_memcache=False) | |
conn = model.make_connection(config, _api_version=datastore_rpc._CLOUD_DATASTORE_V1) | |
# strangely _CreateCloudDatastoreConnection sets the default connection to V1 | |
ctx = ndb.make_context(conn=conn, config=config) | |
ndb.set_context(ctx) | |
user = user_models.User.GetById(email_addr='amohr@farmersbusinessnetwork.com') | |
blockable = Blockable.get_by_id('b125b57caa4334895074afde0b7fdc5a41644488515102a6cb9af13568a07155') | |
# note: I think we're using the wrong datstore client, | |
was_yes_vote = True | |
vote_weight = settings.VOTING_THRESHOLDS[constants.STATE.GLOBALLY_WHITELISTED] | |
vote = voting_api.Vote(user, blockable.key.id(), was_yes_vote, vote_weight) | |
if __name__ == '__main__': | |
logging.basicConfig(level=logging.INFO) | |
parser = argparse.ArgumentParser(description='Demonstrates datastore API operations.') | |
# parser.add_argument('project_id', help='Your cloud project ID.') | |
parser.add_argument('service_account_json', help='Path to service account json file.') | |
args = parser.parse_args() | |
main(args.service_account_json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment