Example #1
0
def send_contact_requested(sid, mes_data):
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(mes_data['to_user_id'])
        data_to_send = {
            'request_status_changed': mes_data,
            'unread': get_unread(usr.id, [])
        }
        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send, sid_for_recipient)
Example #2
0
def send_contact_requested(sid, mes_data):
    log('send_contact_requested', sid, mes_data)
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(mes_data['to_user_id'])
        data_to_send = {
            'request_status_changed': mes_data,
            'unread': get_unread(usr.id, [])
        }
        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send,
                         sid_for_recipient)
def convert_item_to_material(item, feed: NewsFeedCompany):

    # item_date_datetime = grab_datetime_from_item(item)

    existing_material = g.db.query(Material).filter(
        and_(Material.company_id == news_feed.company_id,
             Material.external_url == item['link'],
             Material.source_type == 'rss',
             Material.source_id == feed.id)).first()

    if existing_material:
        app.log.info(
            'for company_news_feed={} material already exists (material={})'.
            format(news_feed.id, existing_material.id))
        return None

    more_properties = try_to_guess_more_properties(item)

    material = Material(company_id=news_feed.company_id,
                        company=news_feed.company,
                        title=item['title'],
                        short=BeautifulSoup(item['description'],
                                            "html.parser").text,
                        external_url=item['link'],
                        source_type='rss',
                        source_id=feed.id,
                        editor=User.get(SYSTEM_USERS.profireader()),
                        **more_properties)

    try:
        downloaded_page = item.get('__downloaded_page', None)
        downloaded_page = downloaded_page.find(
            "meta", {'property': "og:image"}) if downloaded_page else None
        image_in_description = re.match(r'<img[^>]+src="([^"]+)"[^>]*>',
                                        item['description'])
        try_to_grab_illustration(
            material, *[
                downloaded_page.get('content', None)
                if downloaded_page else None,
                item.get('image', None),
                image_in_description.group(1)
                if image_in_description else None,
            ])
    except Exception as e:
        app.log.warning("error while converting rss item to material: `%s`" %
                        (e, ))

    return material
Example #4
0
def send_notification(sid, notification_data):
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(notification_data['to_user_id'])
        n = Notification(to_user_id=usr.id, notification_type=notification_data['notification_type'],
                         notification_data=notification_data, content=notification_data['content'])

        n.save()
        notification = Notification.get(n.id)
        data_to_send = {
            'new_notification': notification.client_message(),
            'unread': get_unread(usr.id, [])}

        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send, sid_for_recipient)
def convert_item_to_material(item, feed:NewsFeedCompany):

    # item_date_datetime = grab_datetime_from_item(item)

    existing_material = g.db.query(Material).filter(and_(
        Material.company_id == news_feed.company_id,
        Material.external_url == item['link'],
        Material.source_type == 'rss',
        Material.source_id == feed.id
    )).first()

    if existing_material:
        app.log.info(
            'for company_news_feed={} material already exists (material={})'.
                format(news_feed.id, existing_material.id))
        return None

    more_properties = try_to_guess_more_properties(item)

    material = Material(company_id=news_feed.company_id,
                        company=news_feed.company,
                        title=item['title'],
                        short=BeautifulSoup(item['description'], "html.parser").text,
                        external_url=item['link'],
                        source_type='rss',
                        source_id=feed.id,
                        editor=User.get(SYSTEM_USERS.profireader()),
                        **more_properties
                        )

    try:
        downloaded_page = item.get('__downloaded_page', None)
        downloaded_page = downloaded_page.find("meta", {'property': "og:image"}) if downloaded_page else None
        image_in_description = re.match(r'<img[^>]+src="([^"]+)"[^>]*>', item['description'])
        try_to_grab_illustration(material, *[
            downloaded_page.get('content', None) if downloaded_page else None,
            item.get('image', None),
            image_in_description.group(1) if image_in_description else None,
            ])
    except Exception as e:
        app.log.warning("error while converting rss item to material: `%s`" % (e, ))


    return material
Example #6
0
def send_notification(sid, notification_data):
    log('send_notification', sid, notification_data)
    with controlled_execution():
        from profapp.models.users import User
        usr = User.get(notification_data['to_user_id'])
        n = Notification(
            to_user_id=usr.id,
            notification_type=notification_data['notification_type'],
            notification_data=notification_data,
            content=notification_data['content'])

        n.save()
        notification = Notification.get(n.id)
        data_to_send = {
            'new_notification': notification.client_message(),
            'unread': get_unread(usr.id, [])
        }

        if usr.id in connected_user_id_sids:
            for sid_for_recipient in connected_user_id_sids[usr.id]:
                sio.emit('general_notification', data_to_send,
                         sid_for_recipient)