Example #1
0
    def post(self):
        args = parser.parse_args()
        profile = db.query(Profile).filter_by(id=args['profile_id']).first()
        miner = db.query(Profile).filter_by(id=args['miner_id']).first()
        previous = db.query(Block).order_by('-id').first()

        data = {
            "message": profile.message,
            "feedback": args["feedback"],
            "initiator": profile.email,
            "miner": miner.email,
            "reward": 30
        }

        nonce, hash, timestamp = Block.pow(data=json.dumps(data),
                                           previous_hash=previous.hash)

        block = Block(data=json.dumps(data),
                      hash=hash,
                      previous_hash=previous.hash,
                      nonce=nonce,
                      creation_date=timestamp)

        miner.thelmies += 30
        profile.thelmies -= 5

        # remove message from profile
        profile.message = ""

        db.add(block)
        db.commit()

        return jsonify(block)
Example #2
0
def harvestLastUpdated(accountId = None):
    query = db.query(Document).filter(
        Document.updated_at < datetime.now() - timedelta(seconds=15),
        Document.tags.any(Tag.slug == 'source'),
        Document.tags.any(Tag.slug == 'harvest'))

    if accountId is not None:
        query.filter(Document.account_id == accountId)

    sources = query.all()
    amount = 0

    for source in sources:
        meta = json.loads(source.meta)

        r = harvest.get_request(meta['url'] % '/invoices?updated_since=%s' % source.updated_at)
        invoices = r.json()

        if len(invoices) > 0:
            print('About to parse %s invoices' % len(invoices))

            amount += 1
            source.updated_at = datetime.now()
            harvest.parse_invoices(invoices, source.account)

    if amount > 0:
        db.commit()

    return amount
Example #3
0
def googleLastUpdated(accountId = None):

    service = get_drive_service()

    query = db.query(Document).filter(
        Document.updated_at < datetime.now() - timedelta(seconds=15),
        Document.tags.any(Tag.slug == 'source'),
        Document.tags.any(Tag.slug == 'google_sheet'))

    if accountId is not None:
        query.filter(Document.account_id == accountId)

    sheets = query.all()
    amount = 0

    for sheet in sheets:
        results = service.files().get(fileId=sheet.uid, fields='name, modifiedTime').execute()

        if datetime.strptime(results['modifiedTime'], "%Y-%m-%dT%H:%M:%S.%fZ") > sheet.updated_at:
            print('This is what we fetched: %s.' % sheet.name)
            sheet.name = results['name']
            sheet.updated_at = datetime.now()
            google.parseGoogleSheet(sheet)
            amount+= 1

    ### Add Documents to DB
    if amount > 0:
        db.commit()

    return amount
Example #4
0
    def put(self, id):
        args = parser.parse_args()
        profile = db.query(Profile).filter_by(id=id).first()

        profile.message = args['message']
        db.commit()

        return jsonify(profile)
Example #5
0
def run_query(query, db):
    db = pms.connect("localhost","sequelhelp_411","abducs411!!!!!", db)
    cursor = db.cursor()
    cursor.execute(query)
    db.commit()

    data = cursor.fetchall()
    db.close()
    return data
Example #6
0
    def post(self):
        args = parser.parse_args()

        profile = Profile(email=args['email'],
                          name=args['name'],
                          password=hashlib.sha224(
                              args['password'].encode('utf-8')).hexdigest(),
                          thelmies=100)
        db.add(profile)
        db.commit()

        return jsonify(profile)
Example #7
0
    def generateFirst(self):

        data = '{"message": "TEX Event Genesis block"}'
        nonce, hash, timestamp = Block.pow(data=data, previous_hash="0")

        first = Block(data=data,
                      hash=hash,
                      previous_hash="0",
                      nonce=nonce,
                      creation_date=timestamp)
        # genesis = blockchain.genesis()
        db.add(first)
        db.commit()
Example #8
0
    ### Add Harvest invoices
    r = requests.get(url % '/invoices', headers=headers)
    parse_invoices(r.json(), cloudokilx, s)

    ## CLOUDOKI
    url = 'https://cloudoki.harvestapp.com%s'
    cloudoki = get_or_create(s, Account, name="Cloudoki")

    ### Add Harvest Clients
    r = requests.get(url % '/clients', headers=headers)
    parse_partners(r.json(), s)

    ### Add Harvest invoices
    r = requests.get(url % '/invoices', headers=headers)  #?page=6
    parse_invoices(r.json(), cloudoki, s)

    ## SAVVY
    url = 'https://savvy.harvestapp.com%s'
    savvy = get_or_create(s, Account, name="Savvy")

    ### Add Harvest Clients
    r = requests.get(url % '/clients', headers=headers)
    parse_partners(r.json(), s)

    ### Add Harvest invoices
    r = requests.get(url % '/invoices', headers=headers)
    parse_invoices(r.json(), savvy, s)

    db.commit()