def get_sms_report_author(report_id, report, user): icon_url_link = None icon_url = get_conf('sms_report_creator_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) author = { 'Source': { 'Name': 'sms_ingest', # actually not used, since providing user below; otherwise coverage name could be used }, 'User': { 'FirstName': get_sms_creator_name(), 'MetaDataIcon': { 'href': icon_url_link }, }, } use_uuid = get_conf('sms_report_creator_uuid') if use_uuid: author['User']['Uuid'] = use_uuid return author
def get_plain_report_author(report_id, report, user): if not user: user = { 'first_name': get_default_author_name(), 'picture_url': get_conf('default_report_author_icon'), 'uuid': get_conf('default_report_author_uuid'), } icon_url_link = None icon_url = None if ('picture_url' in user) and user['picture_url']: icon_url = user['picture_url'] if not icon_url: icon_url = get_conf('default_report_author_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) author = { 'Source': { 'Name': 'citizen_desk', #'internal', }, 'User': { 'MetaDataIcon': { 'href': icon_url_link }, }, } if ('uuid' in user) and user['uuid']: author['User']['Uuid'] = user['uuid'] if (FIELD_UPDATED_USER in user) and user[FIELD_UPDATED_USER]: author['User']['Cid'] = cid_from_update(user[FIELD_UPDATED_USER]) has_a_name = False if ('first_name' in user) and user['first_name']: has_a_name = True author['User']['FirstName'] = user['first_name'] if ('last_name' in user) and user['last_name']: has_a_name = True author['User']['LastName'] = user['last_name'] if not has_a_name: author['User']['FirstName'] = get_default_author_name() return author
def get_plain_report_author(report_id, report, user): if not user: user = { 'first_name': get_default_author_name(), 'picture_url': get_conf('default_report_author_icon'), 'uuid': get_conf('default_report_author_uuid'), } icon_url_link = None icon_url = None if ('picture_url' in user) and user['picture_url']: icon_url = user['picture_url'] if not icon_url: icon_url = get_conf('default_report_author_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) author = { 'Source': { 'Name': 'citizen_desk', #'internal', }, 'User': { 'MetaDataIcon': {'href': icon_url_link}, }, } if ('uuid' in user) and user['uuid']: author['User']['Uuid'] = user['uuid'] if (FIELD_UPDATED_USER in user) and user[FIELD_UPDATED_USER]: author['User']['Cid'] = cid_from_update(user[FIELD_UPDATED_USER]) has_a_name = False if ('first_name' in user) and user['first_name']: has_a_name = True author['User']['FirstName'] = user['first_name'] if ('last_name' in user) and user['last_name']: has_a_name = True author['User']['LastName'] = user['last_name'] if not has_a_name: author['User']['FirstName'] = get_default_author_name() return author
def get_coverage_info(db, coverage_id): coverage_id = _get_id_value(coverage_id) coll = db[COLL_COVERAGES] if type(coverage_id) is ObjectId: return (False, 'old form of coverage info retrieval') else: coverage = coll.find_one({'uuid': coverage_id}) if not coverage: return (False, 'coverage not found') base_url = get_conf('reports_url') reports_url = base_url.replace(PUBLISHED_REPORTS_PLACEHOLDER, urllib.quote_plus(str(coverage_id))) title = '' if ('title' in coverage) and coverage['title']: title = coverage['title'] description = '' if ('description' in coverage) and coverage['description']: description = coverage['description'] active = False if (FIELD_ACTIVE_COVERAGE in coverage) and coverage[FIELD_ACTIVE_COVERAGE]: active = coverage[FIELD_ACTIVE_COVERAGE] info = { 'IsLive': active, 'Title': title, 'Description': description, 'PostPublished': {'href': reports_url,}, } return (True, info)
def get_sms_report_icon(report_id, report, user): icon_url = get_conf('sms_report_creator_icon') icon = { 'Content': {'href': icon_url}, } return icon
def get_sms_report_creator(report_id, report, user): icon_url_link = None icon_url = get_conf('sms_report_creator_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) creator = { 'FirstName': get_sms_creator_name(), 'MetaDataIcon': {'href': icon_url_link}, } use_uuid = get_conf('sms_report_creator_uuid') if use_uuid: creator['Uuid'] = use_uuid return creator
def get_sms_report_icon(report_id, report, user): icon_url = get_conf('sms_report_creator_icon') icon = { 'Content': { 'href': icon_url }, } return icon
def get_plain_report_icon(report_id, report, user): if not user: user = { 'first_name': get_default_author_name(), 'picture_url': get_conf('default_report_author_icon'), 'uuid': get_conf('default_report_author_uuid'), } icon_url = None if ('picture_url' in user) and user['picture_url']: icon_url = user['picture_url'] if not icon_url: icon_url = get_conf('default_report_author_icon') icon = { 'Content': {'href': icon_url}, } return icon
def get_sms_report_creator(report_id, report, user): icon_url_link = None icon_url = get_conf('sms_report_creator_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) creator = { 'FirstName': get_sms_creator_name(), 'MetaDataIcon': { 'href': icon_url_link }, } use_uuid = get_conf('sms_report_creator_uuid') if use_uuid: creator['Uuid'] = use_uuid return creator
def get_plain_report_icon(report_id, report, user): if not user: user = { 'first_name': get_default_author_name(), 'picture_url': get_conf('default_report_author_icon'), 'uuid': get_conf('default_report_author_uuid'), } icon_url = None if ('picture_url' in user) and user['picture_url']: icon_url = user['picture_url'] if not icon_url: icon_url = get_conf('default_report_author_icon') icon = { 'Content': { 'href': icon_url }, } return icon
def get_sms_report_author(report_id, report, user): icon_url_link = None icon_url = get_conf('sms_report_creator_icon') if icon_url: icon_url_template = get_conf('icon_url') icon_url_link = icon_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, str(report_id)) author = { 'Source': { 'Name': 'sms_ingest', # actually not used, since providing user below; otherwise coverage name could be used }, 'User': { 'FirstName': get_sms_creator_name(), 'MetaDataIcon': {'href': icon_url_link}, }, } use_uuid = get_conf('sms_report_creator_uuid') if use_uuid: author['User']['Uuid'] = use_uuid return author
def get_coverage_list(db): base_url = get_conf('coverage_info_url') coll = db[COLL_COVERAGES] coverages = [] cursor = coll.find({ FIELD_ACTIVE_COVERAGE: True }, { '_id': True, 'title': True, 'description': True, 'uuid': True }).sort([('_id', 1)]) for entry in cursor: if 'uuid' not in entry: continue cov_id = entry['uuid'] coverage_url = base_url.replace(COVERAGE_PLACEHOLDER, urllib.quote_plus(str(cov_id))) if 'title' not in entry: continue one_description = '' if ('description' in entry) and entry['description']: one_description = entry['description'] one_cov = { 'href': coverage_url, 'Title': entry['title'], 'Description': one_description, } coverages.append(one_cov) res = { 'total': len(coverages), 'limit': len(coverages), 'offset': 0, 'BlogList': coverages } return (True, res)
def extract_annotation(db, report): annotation = {} for notice_type in NOTICES_USED: annotation[notice_type] = None status_position = get_status_display_position() comment_position = '' for one_pos in NOTICES_USED: if one_pos != status_position: comment_position = one_pos break if get_conf('use_status_for_output'): status = extract_annotation_status(db, report) annotation[status_position] = status comment = extract_annotation_comment(db, report) annotation[comment_position] = comment return annotation
def get_coverage_list(db): base_url = get_conf('coverage_info_url') coll = db[COLL_COVERAGES] coverages = [] cursor = coll.find({FIELD_ACTIVE_COVERAGE: True}, {'_id': True, 'title': True, 'description': True, 'uuid': True}).sort([('_id', 1)]) for entry in cursor: if 'uuid' not in entry: continue cov_id = entry['uuid'] coverage_url = base_url.replace(COVERAGE_PLACEHOLDER, urllib.quote_plus(str(cov_id))) if 'title' not in entry: continue one_description = '' if ('description' in entry) and entry['description']: one_description = entry['description'] one_cov = { 'href': coverage_url, 'Title': entry['title'], 'Description': one_description, } coverages.append(one_cov) res = { 'total': len(coverages), 'limit': len(coverages), 'offset': 0, 'BlogList': coverages } return (True, res)
def get_coverage_info(db, coverage_id): coverage_id = _get_id_value(coverage_id) coll = db[COLL_COVERAGES] if type(coverage_id) is ObjectId: return (False, 'old form of coverage info retrieval') else: coverage = coll.find_one({'uuid': coverage_id}) if not coverage: return (False, 'coverage not found') base_url = get_conf('reports_url') reports_url = base_url.replace(PUBLISHED_REPORTS_PLACEHOLDER, urllib.quote_plus(str(coverage_id))) title = '' if ('title' in coverage) and coverage['title']: title = coverage['title'] description = '' if ('description' in coverage) and coverage['description']: description = coverage['description'] active = False if (FIELD_ACTIVE_COVERAGE in coverage) and coverage[FIELD_ACTIVE_COVERAGE]: active = coverage[FIELD_ACTIVE_COVERAGE] info = { 'IsLive': active, 'Title': title, 'Description': description, 'PostPublished': { 'href': reports_url, }, } return (True, info)
def get_sms_creator_name(): sms_creator_name = get_conf('sms_report_creator_name') if not sms_creator_name: sms_creator_name = 'SMS' return sms_creator_name
def get_coverage_published_report_list(db, coverage_id, cid_last): ''' SMS: original/transcribed text, can have two comments both creator and author are sms-based user/citizen, of smsblog source type (source name is name of sms feed) http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/854 tweet: the original tweet (with some predefined adjusting), without any (other) changes, can have two comments creator is a local user, author is just the twitter source http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/855 plain: a text http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/856 link: a web link http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/38/Post/1070 other: ignoring by now ''' try: coverage_id = _get_id_value(coverage_id) except: pass res_none = {'total': 0, 'limit': 0, 'offset': 0, 'PostList': []} coll = db[COLL_COVERAGES] if type(coverage_id) is ObjectId: return (False, 'old form of coverage reports retrieval') else: coverage = coll.find_one({'uuid': coverage_id}) if not coverage: return (False, 'coverage not found') if (FIELD_ACTIVE_COVERAGE not in coverage) or (not coverage[FIELD_ACTIVE_COVERAGE]): return (True, res_none) author_url_template = get_conf('author_url') creator_url_template = get_conf('creator_url') coll = db[COLL_REPORTS] reports = [] put_up_border = datetime.datetime.utcfromtimestamp(0) search_spec = { 'coverages.outgested': { '$in': [coverage_id, coverage['_id']] }, FIELD_DECAYED_REPORT: { '$ne': True }, } if cid_last: update_last = update_from_cid(cid_last) search_spec[FIELD_UPDATED_REPORT] = {'$gt': update_last} put_up_border = update_last else: search_spec[FIELD_UPDATED_REPORT] = {'$exists': True} # probably some adjusted dealing with: local, summary, unpublished/deleted reports cursor = coll.find(search_spec).sort([(FIELD_UPDATED_REPORT, 1)]) for entry in cursor: if 'feed_type' not in entry: entry['feed_type'] = DEFAULT_FIELD_TYPE with_fields = True for key in [ FIELD_UPDATED_REPORT, FIELD_UUID_REPORT, 'feed_type', 'texts', 'coverages' ]: if (key not in entry) or (not entry[key]): with_fields = False break if not with_fields: continue if type(entry['coverages']) is not dict: continue if ('published' not in entry['coverages']): continue if type(entry['coverages']['published']) not in (list, tuple): continue feed_type = entry['feed_type'] if feed_type not in OUTPUT_FEED_TYPES: continue content = None meta = None post_type_key = 'normal' if 'sms' == feed_type: adapted = adapt_sms_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'tweet' == feed_type: adapted = adapt_tweet_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'plain' == feed_type: adapted = adapt_plain_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'web_link' == feed_type: adapted = adapt_link_report(db, entry) content = adapted['content'] meta = adapted['meta'] post_type_key = 'link' use_cid = 0 if FIELD_UPDATED_REPORT in entry: use_cid = cid_from_update(entry[FIELD_UPDATED_REPORT]) one_report = { 'CId': use_cid, 'IsPublished': 'True', 'Type': { 'Key': post_type_key }, 'Content': content, 'Meta': meta, } if FIELD_UUID_REPORT in entry: one_report['Uuid'] = entry[FIELD_UUID_REPORT] if (FIELD_PUTUP_REPORT in entry) and entry[FIELD_PUTUP_REPORT]: try: if entry[FIELD_PUTUP_REPORT] > put_up_border: one_report['PutUp'] = 'True' except: pass if coverage_id not in entry['coverages']['published']: if coverage['_id'] not in entry['coverages']['published']: one_report['DeletedOn'] = '01/01/70 12:01 AM' link_id = urllib.quote_plus(str(entry['_id'])) author_url = author_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, link_id) creator_url = creator_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, link_id) one_report['Author'] = {'href': author_url} one_report['Creator'] = {'href': creator_url} reports.append(one_report) res = { 'total': len(reports), 'limit': len(reports), 'offset': 0, 'PostList': reports } return (True, res)
def get_status_display_position(): status_position = get_conf('status_display_position') if status_position not in NOTICES_USED: status_position = NOTICE_STATUS_DEFAULT return status_position
def get_default_author_name(): default_author_name = get_conf('default_report_author_name') if not default_author_name: default_author_name = 'Citizen Desk' return default_author_name
def get_coverage_published_report_list(db, coverage_id, cid_last): ''' SMS: original/transcribed text, can have two comments both creator and author are sms-based user/citizen, of smsblog source type (source name is name of sms feed) http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/854 tweet: the original tweet (with some predefined adjusting), without any (other) changes, can have two comments creator is a local user, author is just the twitter source http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/855 plain: a text http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/1/Post/856 link: a web link http://sourcefabric.superdesk.pro/resources/LiveDesk/Blog/38/Post/1070 other: ignoring by now ''' try: coverage_id = _get_id_value(coverage_id) except: pass res_none = { 'total': 0, 'limit': 0, 'offset': 0, 'PostList': [] } coll = db[COLL_COVERAGES] if type(coverage_id) is ObjectId: return (False, 'old form of coverage reports retrieval') else: coverage = coll.find_one({'uuid': coverage_id}) if not coverage: return (False, 'coverage not found') if (FIELD_ACTIVE_COVERAGE not in coverage) or (not coverage[FIELD_ACTIVE_COVERAGE]): return (True, res_none) author_url_template = get_conf('author_url') creator_url_template = get_conf('creator_url') coll = db[COLL_REPORTS] reports = [] put_up_border = datetime.datetime.utcfromtimestamp(0) search_spec = { 'coverages.outgested': {'$in': [coverage_id, coverage['_id']]}, FIELD_DECAYED_REPORT: {'$ne': True}, } if cid_last: update_last = update_from_cid(cid_last) search_spec[FIELD_UPDATED_REPORT] = {'$gt': update_last} put_up_border = update_last else: search_spec[FIELD_UPDATED_REPORT] = {'$exists': True} # probably some adjusted dealing with: local, summary, unpublished/deleted reports cursor = coll.find(search_spec).sort([(FIELD_UPDATED_REPORT, 1)]) for entry in cursor: if 'feed_type' not in entry: entry['feed_type'] = DEFAULT_FIELD_TYPE with_fields = True for key in [FIELD_UPDATED_REPORT, FIELD_UUID_REPORT, 'feed_type', 'texts', 'coverages']: if (key not in entry) or (not entry[key]): with_fields = False break if not with_fields: continue if type(entry['coverages']) is not dict: continue if ('published' not in entry['coverages']): continue if type(entry['coverages']['published']) not in (list, tuple): continue feed_type = entry['feed_type'] if feed_type not in OUTPUT_FEED_TYPES: continue content = None meta = None post_type_key = 'normal' if 'sms' == feed_type: adapted = adapt_sms_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'tweet' == feed_type: adapted = adapt_tweet_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'plain' == feed_type: adapted = adapt_plain_report(db, entry) content = adapted['content'] meta = adapted['meta'] if 'web_link' == feed_type: adapted = adapt_link_report(db, entry) content = adapted['content'] meta = adapted['meta'] post_type_key = 'link' use_cid = 0 if FIELD_UPDATED_REPORT in entry: use_cid = cid_from_update(entry[FIELD_UPDATED_REPORT]) one_report = { 'CId': use_cid, 'IsPublished': 'True', 'Type': {'Key': post_type_key}, 'Content': content, 'Meta': meta, } if FIELD_UUID_REPORT in entry: one_report['Uuid'] = entry[FIELD_UUID_REPORT] if (FIELD_PUTUP_REPORT in entry) and entry[FIELD_PUTUP_REPORT]: try: if entry[FIELD_PUTUP_REPORT] > put_up_border: one_report['PutUp'] = 'True' except: pass if coverage_id not in entry['coverages']['published']: if coverage['_id'] not in entry['coverages']['published']: one_report['DeletedOn'] = '01/01/70 12:01 AM' link_id = urllib.quote_plus(str(entry['_id'])) author_url = author_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, link_id) creator_url = creator_url_template.replace(REPORT_LINK_ID_PLACEHOLDER, link_id) one_report['Author'] = {'href': author_url} one_report['Creator'] = {'href': creator_url} reports.append(one_report) res = { 'total': len(reports), 'limit': len(reports), 'offset': 0, 'PostList': reports } return (True, res)