Esempio n. 1
0
def get_newregister():
    logconsole.info("new register called with "+str(request.json))
    if not request.json or not 'id' in request.json:
        abort(400)
    user = {
        'id': request.json['id'],
        'wallet': '0x123415235',
        'created_at': time.time()
    }
    user_id=spot_db.getUserID(request.json['id'])
    refer = None
    if 'ref' in request.json:
       refer = request.json['ref']
    if user_id is None :
       spot_db.newUser(request.json['id'])
       user_id = spot_db.getUserID(request.json['id'])
       spot_db.giftBill(user_id, spot_db.last_day_of_month(datetime.datetime.fromtimestamp(time.time())), 20)
    props = spot_db.getUserProperties(user_id)
    logconsole.info("new registering user "+request.json['id']+" user_id="+user_id+" props="+str(props))
    if refer != None:
       (closedRefCnt,sender_id) = spot_db.closeReferral(refer,request.json['id'])
       if closedRefCnt is None or sender_id is None or closedRefCnt == 0 :
          logconsole.info("prevented attempt to use non existing or closed referral user_id="+user_id+" ref="+refer)
       else:
          spot_db.giftBill(user_id, spot_db.last_day_of_month(datetime.datetime.fromtimestamp(time.time())), 10)
          spot_db.giftBill(sender_id, spot_db.last_day_of_month(datetime.datetime.fromtimestamp(time.time())), 10)
          logconsole.info("reference accepted, tokens granted, user_id="+user_id+" sender_id="+sender_id+" ref="+refer)

    user['roles']=props[0]
    logconsole.info("new registered user "+request.json['id']+" db key ="+user_id+" props="+str(props))
    return jsonify( { 'user': make_public_user(user) } ), 201
Esempio n. 2
0
def get_register():
    logconsole.info("register called with " + str(request.json))
    if not request.json or not 'id' in request.json:
        abort(400)
    user = {
        'id': request.json['id'],
        'wallet': '0x12341q42134khjsagdf2345235',
        'created_at': time.time()
    }
    informer_id = spot_db.getUserID(request.json['id'])
    refer = None
    if 'ref' in request.json:
        refer = request.json['ref']
    if informer_id is None:
        spot_db.newUser(request.json['id'])
        informer_id = spot_db.getUserID(request.json['id'])
        spot_db.giftBill(
            informer_id,
            spot_db.last_day_of_month(
                datetime.datetime.fromtimestamp(time.time())), 20)
    props = spot_db.getUserProperties(informer_id)
    logconsole.info("registering user " + request.json['id'] +
                    " informer_id=" + informer_id + " props=" + str(props))
    if refer != None:
        sender_id = spot_db.getSenderId(refer)
        if sender_id == None:
            logconsole.info(
                "attempt to re-use closed reference prevented informer_id=" +
                informer_id + " ref=" + refer)
        else:
            if sender_id == informer_id:
                logconsole.info(
                    "attempt to self refer prevented informer_id=" +
                    informer_id + " ref=" + refer)
            else:
                rc = spot_db.closeReferrence(refer, informer_id)
                if rc != 0:
                    abort(rc)
                spot_db.giftBill(
                    informer_id,
                    spot_db.last_day_of_month(
                        datetime.datetime.fromtimestamp(time.time())), 10)
                spot_db.giftBill(
                    sender_id,
                    spot_db.last_day_of_month(
                        datetime.datetime.fromtimestamp(time.time())), 10)
                logconsole.info(
                    "reference accepted, tokens granted, informer_id=" +
                    informer_id + " sender_id=" + sender_id + " ref=" + refer)

    user['roles'] = props[0]
    logconsole.info("registered user " + request.json['id'] + " db key =" +
                    informer_id + " props=" + str(props))
    return jsonify({'user': make_public_user(user)}), 201
Esempio n. 3
0
def calc_balance(user, dfrom, dto):
    logconsole.info("start calc balance for " + user + " dfrom=" + str(dfrom) +
                    " dto=" + str(dto))
    uid = spot_db.getUserID(user)
    informed = spot_db.getInformedSpots(uid, dfrom, dto)
    mnat = None
    mxat = None
    if informed == None:
        informed_qty = 0
        mnat = dfrom
        mxat = dto
    else:
        informed_qty = informed[0]
        mnat = informed[2]
        mxat = informed[3]
    occupied = spot_db.getOccupiedSpots(uid, mnat, mxat)
    if occupied == None:
        occupied_qty = 0
    else:
        occupied_qty = occupied[0]
    logconsole.info("user="******"; mnat=" + str(mnat) + "; mxat=" +
                    str(mxat) + " informed_qty=" + str(informed_qty) +
                    " occupied_qty=" + str(occupied_qty))
    logconsole.info("end calc balance for " + user + " dfrom=" + str(dfrom) +
                    " dto=" + str(dto))
    return (user, uid, mnat, mxat, informed_qty, occupied_qty)
Esempio n. 4
0
def get_referral():
    logconsole.info("referral called with " + str(request.json))
    if not request.json or not 'id' in request.json or not 'links' in request.json:
        logconsole.info("returning 400 id " + request.json['id'] +
                        " request " + str(request))
        abort(400)

    reference = {'id': request.json['id'], 'rejected': []}
    referralsCnt = spot_db.countReferrals(request.json['id'])
    logconsole.info("number of user " + request.json['id'] +
                    " referrals is equal " + str(referralsCnt))
    non_members = []
    for link_hash in request.json['links']:
        if (len(non_members) + referralsCnt) >= 30:
            logconsole.info("user " + request.json['id'] +
                            " has referred plenty, preventing mass referrals")
            reference['rejected'].append(link_hash)
        else:
            if link_hash == request.json['id']:
                logconsole.info("self reference attempt with link_hash " +
                                link_hash + " prevented")
                reference['rejected'].append(link_hash)
            else:
                user_id = spot_db.getUserID(link_hash)
                if user_id is None:
                    logconsole.info("user does not exist with link_hash " +
                                    link_hash +
                                    " checking if referal was sent")
                    ref_id = spot_db.getReferral(link_hash)
                    if ref_id is None:
                        logconsole.info("referal has not been sent for " +
                                        link_hash)
                        non_members.append(link_hash)
                    else:
                        logconsole.info(
                            "referal has already been sent for link_hash " +
                            link_hash)
                        reference['rejected'].append(link_hash)
                else:
                    logconsole.info("user exists with link_hash " + link_hash)
                    reference['rejected'].append(link_hash)
    if len(non_members) > 0:  # some candidate not registered yet
        logconsole.info("adding non_members " + str(non_members))
        if not 'dryrun' in request.json:
            ref_id = spot_db.newReferral(request.json['id'], non_members)
            if ref_id is None:
                logconsole.info("returning 403 id " + request.json['id'])
                abort(403)
            reference['ref'] = ref_id
    else:
        logconsole.info("all referral candidates were rejected")

    logconsole.info("referral response " + str(reference))
    return jsonify({'referral': make_public_referral(reference)}), 201
Esempio n. 5
0
 def traverse_dataset(self, dsid, func=None):
     self._step_started_at = time.time()
     cnt = 0
     npcnt = 0
     informer_id = spot_db.getUserID("strix")  # rerpot as huhulaspot
     try:
         payload = {}
         r = self.postit(
             self.url + "/v1/features/%s?api_key=%s" % (dsid, self.api_key),
             payload)
         jlst = json.loads(r.text)
         for jj in jlst["features"]:
             capacity = str(jj["properties"]["Attributes"].get(
                 "CarCapacity", "0")).replace("null", "1")
             if capacity == None or capacity == "None":
                 capacity = 0
             name = jj["properties"]["Attributes"].get("ParkingName", "not")
             tpe = jj["geometry"].get("type", "")
             if tpe == "Point":
                 coord = jj["geometry"]["coordinates"]
             elif tpe == "MultiLineString":
                 coord = jj["geometry"]["coordinates"][0][0]
             if name == "not" or capacity == 0 or len(coord) != 2:
                 npcnt += 1
                 continue
             lat = coord[1]
             lon = coord[0]
             attr = jj["properties"]["Attributes"]
             meter = jj["properties"]["Attributes"].get(
                 "NumberOfParkingMeter", "0")
             phone = jj["properties"]["Attributes"].get("OrgPhone", "")
             district = jj["properties"]["Attributes"].get("District", "")
             #                description = jj["properties"]["Attributes"].get("LocationDescription", "")
             #                area = jj["properties"]["Attributes"].get("AdmArea", "")
             cnt += 1
             logging.info("dsid=" + str(dsid) + "; lat=" + str(lat) +
                          "; lon=" + str(lon) + "; name=" + name +
                          "; capacity=" + str(capacity) + " meter=" +
                          str(meter))
             if func != None:
                 func(informer_id, lat, lon, capacity)
     except Exception as error:
         jts = traceback.format_exc()
         logconsole.error(jts)
     logging.info("dataset " + str(dsid) + "; element count = " + str(cnt) +
                  " not a parking cnt=" + str(npcnt))
     time.sleep(3)
     return cnt