Exemplo n.º 1
0
def initiate():
    fixedNumber = ""
    print request.form['number']
    print "A"
    print request.values.get('number')
    for elem in request.values.get('number'):
        if elem.isnumeric():
            fixedNumber = fixedNumber + str(elem)
    print "B"
    if len(fixedNumber) == 10:
        fixedNumber = "+1" + fixedNumber
    elif len(fixedNumber) == 11:
        fixedNumber = "+" + fixedNumber

    print "C"
    r = Record(fixedNumber, request.values.get("image"))
    phones = Record.query.filter_by(phone=fixedNumber).all()

    print "D"
    if phones == None:
        db.session.add(r)
        db.session.commit()
    else:
        pass

    print "E"
    image(fixedNumber, request.values.get("image"))
    client = TwilioRestClient(twilio_account_sid, twilio_auth_token)
    message = client.messages.create(to=fixedNumber, from_=twilio_number, body="Hey! Want to HEAR what your PICTURE looks like? Send \"yes\" to this SMS!")

    return "None"
Exemplo n.º 2
0
def create():
    # This will deserialize the JSON from insomnia
    schema = RecordSchema()

    try:
        # attempt to convert the JSON into a dict
        data = schema.load(request.get_json())
        # Use that to create a record object
        record = Record(**data, createdBy=g.current_user)
        # store it in the database
        db.commit()
    except ValidationError as err:
        # if the validation fails, send back a 422 response
        return jsonify({'message': 'Validation failed', 'errors': err.messages}), 422

    # otherwise, send back the record data as JSON
    return schema.dumps(record), 201
Exemplo n.º 3
0
 def mapResult(self, cursor):
     #TODO: fetch later
     rows = cursor.fetchall()
     columns = [c.name for c in cursor.description]
     return [Record(dict(zip(columns, row))) for row in rows]
Exemplo n.º 4
0
    vinyl = Medium(name='Vinyl')


    User(
    username='******',
    email='*****@*****.**',
    password_hash=schema.generate_hash('pass'),
    )




    first = Record(
        artist="First",
        title="Title",
        cover="/images/one.png",
        description="""Series to the cult groove and the short bass style compositions and producers across the styles of the world of sound are subtle and all the album moves and the steppers of the other instruments in the spiritual, and the title Unit and late ‘80s acts and stares at the style scene and collaboration
        Recorded and studio series and produced by the listeners of the most story heard of their share of ‘The Works’ get the most proof string of ‘Mark One Time’""",
        mediums=[cd, tape]
        )


    second = Record(
        artist="Second",
        title="Title",
        cover="/images/two.png",
        description="""A sound in the band of electronic music of electronic musics and hardcore and sounds of sounds of the missing for those transformation and the distance of experience of the strongest design of ‘Billish Martin' and the sound of his recorded by Michelle Lear. The series of field recordings animation
        Del and strangely styles of a super sound of the sense to the world""",
        mediums=[cd, tape, download]

        )
Exemplo n.º 5
0
    def write_to_db(self):
        """
        Diff record in webpage and db and update/create/skip records
        :return:
        """
        # reset the counter
        self.received_elements_in_this_cycle_count = 0  # items received in this process cycle

        skipped_entities_count = 0
        items_to_process = self.items_to_process
        entities_to_create = self.entities_to_create
        entities_to_update = self.entities_to_update
        self.items_to_process = []
        self.entities_to_create = []
        self.entities_to_update = []

        database_response_entities = self.recordTableDatabaseExecutor.query_range(
            self.current_min_user_id, self.current_max_user_id)

        database_response_dict = {}

        new_entities_might_need_deleting = set()

        for db_entity in database_response_entities:
            database_response_dict[(db_entity.user_id,
                                    db_entity.subject_id)] = db_entity
            if self.entities_seen.get(db_entity.user_id) is None or db_entity.subject_id not in \
                    self.entities_seen.get(db_entity.user_id):
                new_entities_might_need_deleting.add(
                    (db_entity.user_id, db_entity.subject_id))

        # first we assume all records from db need to be deleted

        self.entities_might_need_deleting.update(
            new_entities_might_need_deleting)

        for record in items_to_process:
            primary_key_from_scrapy_item = (record['user_id'],
                                            record['subject_id'])

            entity_in_db = database_response_dict.get(
                primary_key_from_scrapy_item)
            if entity_in_db:
                # if the record is in scrapy's response, which indicates it's still on web page, remove it from the set
                try:
                    self.entities_might_need_deleting.remove(
                        primary_key_from_scrapy_item)
                except KeyError:
                    # entity might not exist in deleting set, in such case just ignore the error
                    pass
                difference = entity_in_db.diff_self_with_input(record)
                if len(list(difference)) > 0:
                    # db/API contain entity and it has difference, overwriting data in db
                    entity_in_db.set_attribute(record)
                    entities_to_update.append(entity_in_db)
                else:
                    # db/API contain entity but nothing changes, skipping it
                    skipped_entities_count += 1
            else:
                # record has been parsed in self.process_item(), doesn't need to be parsed again
                entity = Record(record, False)
                entities_to_create.append(entity)

        start_id = self.current_min_user_id
        end_id = self.current_max_user_id
        logger.info('Creating %s new instances in user_id range (%s, %s)',
                    len(entities_to_create), start_id, end_id)
        created_entities = self.recordTableDatabaseExecutor.create(
            entities_to_create)
        self.stats['created_entities'] += created_entities

        self.stats['skipped_entities'] += skipped_entities_count
        logger.info(
            'Skipping %s existed instances in range (%s, %s) as there\'s no difference',
            skipped_entities_count, start_id, end_id)

        logger.info('Updating %s existed instances in range (%s, %s)',
                    len(entities_to_update), start_id, end_id)
        updated_entities = self.recordTableDatabaseExecutor.update(
            entities_to_update)
        self.stats['updated_entities'] += updated_entities