def twitter_card(userid): username, full_name, catchphrase, profile_text, config, twitter = d.execute( "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value " "FROM profile pr " "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' " "WHERE pr.userid = %i", [userid], ["single"]) ret = { 'card': 'summary', 'url': d.absolutify_url('/~%s' % (username, )), 'title': '%s on Weasyl' % (full_name, ), } if catchphrase: description = '"%s"' % (catchphrase, ) elif profile_text: description = strip_html(profile_text) else: description = "[%s has an empty profile, but is eggcelent!]" % ( full_name, ) ret['description'] = d.summarize(description) media_items = media.get_user_media(userid) ret['image:src'] = d.absolutify_url( media_items['avatar'][0]['display_url']) if twitter: ret['creator'] = '@%s' % (twitter.lstrip('@'), ) return ret
def twitter_card(userid): username, full_name, catchphrase, profile_text, config, twitter = d.execute( "SELECT pr.username, pr.full_name, pr.catchphrase, pr.profile_text, pr.config, ul.link_value " "FROM profile pr " "LEFT JOIN user_links ul ON pr.userid = ul.userid AND ul.link_type = 'twitter' " "WHERE pr.userid = %i", [userid], ["single"]) ret = { 'card': 'summary', 'url': d.absolutify_url('/~%s' % (username,)), 'title': '%s on Weasyl' % (full_name,), } if catchphrase: description = '"%s"' % (catchphrase,) elif profile_text: description = strip_html(profile_text) else: description = "[%s has an empty profile, but is eggcelent!]" % (full_name,) ret['description'] = d.summarize(description) media_items = media.get_user_media(userid) ret['image:src'] = d.absolutify_url(media_items['avatar'][0]['display_url']) if twitter: ret['creator'] = '@%s' % (twitter.lstrip('@'),) return ret
def fake_media_items(charid, userid, login, settings, absolutify=False): submission_url = define.cdnify_url(define.url_make( charid, "char/submit", query=[userid, settings], file_prefix=login)) cover_url = define.cdnify_url(define.url_make( charid, "char/cover", query=[settings], file_prefix=login)) thumbnail_url = define.cdnify_url(define.url_make( charid, "char/thumb", query=[settings])) if absolutify: submission_url = define.absolutify_url(submission_url) cover_url = define.absolutify_url(cover_url) thumbnail_url = define.absolutify_url(thumbnail_url) return { "submission": [{ "display_url": submission_url, "described": { "cover": [{ "display_url": cover_url, }], }, }], "thumbnail-generated": [{ "display_url": thumbnail_url, }], "cover": [{ "display_url": cover_url, "described": { "submission": [{ "display_url": submission_url, }], }, }], }
def twitter_card(submitid): query = d.execute( """ SELECT su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating FROM submission su INNER JOIN profile pr USING (userid) LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter' WHERE submitid = %i LIMIT 1 """, [submitid], ["single"]) if not query: raise WeasylError("submissionRecordMissing") title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query if 'h' in settings: raise WeasylError("submissionRecordMissing") elif 'f' in settings: raise WeasylError("FriendsOnly") if 'v' in settings: content = d.text_first_line(content, strip=True) content = d.summarize(html.strip_html(content)) if not content: content = "[This submission has no description.]" ret = { 'url': d.absolutify_url('/submission/%s/%s' % (submitid, text.slug_for(title))), } if twitter: ret['creator'] = '@%s' % (twitter.lstrip('@'), ) ret['title'] = title else: ret['title'] = '%s by %s' % (title, full_name) if ratings.CODE_MAP[rating].minimum_age >= 18: ret['card'] = 'summary' ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com' return ret ret['description'] = content subcat = subtype / 1000 * 1000 media_items = media.get_submission_media(submitid) if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'): ret['card'] = 'photo' ret['image:src'] = d.absolutify_url( media_items['submission'][0]['display_url']) else: ret['card'] = 'summary' thumb = media_items.get('thumbnail-custom') or media_items.get( 'thumbnail-generated') if thumb: ret['image:src'] = d.absolutify_url(thumb[0]['display_url']) return ret
def twitter_card(submitid): query = d.execute(""" SELECT su.title, su.settings, su.content, su.subtype, su.userid, pr.username, pr.full_name, pr.config, ul.link_value, su.rating FROM submission su INNER JOIN profile pr USING (userid) LEFT JOIN user_links ul ON su.userid = ul.userid AND ul.link_type = 'twitter' WHERE submitid = %i LIMIT 1 """, [submitid], ["single"]) if not query: raise WeasylError("submissionRecordMissing") title, settings, content, subtype, userid, username, full_name, config, twitter, rating = query if 'h' in settings: raise WeasylError("submissionRecordMissing") elif 'f' in settings: raise WeasylError("FriendsOnly") if 'v' in settings: content = d.text_first_line(content, strip=True) content = d.summarize(html.strip_html(content)) if not content: content = "[This submission has no description.]" ret = { 'url': d.absolutify_url( '/submission/%s/%s' % (submitid, text.slug_for(title))), } if twitter: ret['creator'] = '@%s' % (twitter.lstrip('@'),) ret['title'] = title else: ret['title'] = '%s by %s' % (title, full_name) if ratings.CODE_MAP[rating].minimum_age >= 18: ret['card'] = 'summary' ret['description'] = 'This image is rated 18+ and only viewable on weasyl.com' return ret ret['description'] = content subcat = subtype / 1000 * 1000 media_items = media.get_submission_media(submitid) if subcat == m.ART_SUBMISSION_CATEGORY and media_items.get('submission'): ret['card'] = 'photo' ret['image:src'] = d.absolutify_url(media_items['submission'][0]['display_url']) else: ret['card'] = 'summary' thumb = media_items.get('thumbnail-custom') or media_items.get('thumbnail-generated') if thumb: ret['image:src'] = d.absolutify_url(thumb[0]['display_url']) return ret
def select_view_api(userid, journalid, anyway=False, increment_views=False): rating = d.get_rating(userid) journal = _select_journal_and_check( userid, journalid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) content = files.read(files.make_resource(userid, journalid, 'journal/submit')) return { 'journalid': journalid, 'title': journal['title'], 'owner': journal['username'], 'owner_login': d.get_sysname(journal['username']), 'owner_media': api.tidy_all_media( media.get_user_media(journal['userid'])), 'content': text.markdown(content), 'tags': searchtag.select(journalid=journalid), 'link': d.absolutify_url('/journal/%d/%s' % (journalid, text.slug_for(journal['title']))), 'type': 'journal', 'rating': ratings.CODE_TO_NAME[journal['rating']], 'views': journal['page_views'], 'favorites': favorite.count(journalid, 'journal'), 'comments': comment.count(journalid, 'journal'), 'favorited': favorite.check(userid, journalid=journalid), 'friends_only': 'f' in journal['settings'], 'posted_at': d.iso8601(journal['unixtime']), }
def select_view_api(userid, charid, anyway=False, increment_views=False): rating = define.get_rating(userid) query = _select_character_and_check( userid, charid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) login = define.get_sysname(query.username) return { 'charid': charid, 'owner': query.username, 'owner_login': login, 'owner_media': api.tidy_all_media(media.get_user_media(query.userid)), 'posted_at': define.iso8601(query.unixtime), 'title': query.char_name, 'age': query.age, 'gender': query.gender, 'height': query.height, 'weight': query.weight, 'species': query.species, 'content': text.markdown(query.content), 'rating': ratings.CODE_TO_NAME[query.rating], 'favorited': favorite.check(userid, charid=charid), 'views': query.page_views, 'friends_only': 'f' in query.settings, 'favorites': favorite.count(charid, 'character'), 'comments': comment.count(charid, 'character'), 'media': fake_media_items(charid, query.userid, login, query.settings, absolutify=True), 'tags': searchtag.select(charid=charid), 'type': 'character', 'link': define.absolutify_url('/character/%d/%s' % (charid, text.slug_for(query.char_name))), }
def select_view_api(userid, submitid, anyway=False, increment_views=False): rating = d.get_rating(userid) db = d.connect() sub = db.query(orm.Submission).get(submitid) if sub is None or 'hidden' in sub.settings: raise WeasylError("submissionRecordMissing") sub_rating = sub.rating.code if 'friends-only' in sub.settings and not frienduser.check(userid, sub.userid): raise WeasylError("submissionRecordMissing") elif sub_rating > rating and userid != sub.userid: raise WeasylError("RatingExceeded") elif not anyway and ignoreuser.check(userid, sub.userid): raise WeasylError("UserIgnored") elif not anyway and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") description = sub.content embedlink = None if 'embedded-content' in sub.settings: embedlink, _, description = description.partition('\n') elif 'gdocs-embed' in sub.settings: embedlink = sub.google_doc_embed.embed_url views = sub.page_views if increment_views and d.common_view_content(userid, submitid, 'submit'): views += 1 return { 'submitid': submitid, 'title': sub.title, 'owner': sub.owner.profile.username, 'owner_login': sub.owner.login_name, 'owner_media': api.tidy_all_media(media.get_user_media(sub.userid)), 'media': api.tidy_all_media(media.get_submission_media(submitid)), 'description': text.markdown(description), 'embedlink': embedlink, 'folderid': sub.folderid, 'folder_name': sub.folder.title if sub.folderid else None, 'posted_at': d.iso8601(sub.unixtime), 'tags': searchtag.select(submitid=submitid), 'link': d.absolutify_url("/submission/%d/%s" % (submitid, text.slug_for(sub.title))), 'type': 'submission', 'subtype': m.CATEGORY_PARSABLE_MAP[sub.subtype // 1000 * 1000], 'rating': sub.rating.name, 'views': views, 'favorites': favorite.count(submitid), 'comments': comment.count(submitid), 'favorited': favorite.check(userid, submitid=submitid), 'friends_only': 'friends-only' in sub.settings, }
def _post_to_twitter_about(submitid, title, rating, tags): url = d.absolutify_url('/submission/%s/%s' % (submitid, text.slug_for(title))) st = d.meta.tables['searchtag'] sms = d.meta.tables['searchmapsubmit'] q = (sa.select([st.c.title]).select_from( st.join(sms, st.c.tagid == sms.c.tagid)).where( st.c.title.in_(t.lower() for t in tags)).group_by( st.c.title).order_by(sa.func.count().desc())) account = 'WeasylCritique' if rating in (ratings.MATURE.code, ratings.EXPLICIT.code): account = 'WZLCritiqueNSFW' length = 26 selected_tags = [] db = d.connect() for tag, in db.execute(q): if len(tag) + 2 + length > 140: break selected_tags.append('#' + tag) length += len(tag) + 2 twits.post(account, u'%s %s' % (url, ' '.join(selected_tags)))
def _post_to_twitter_about(submitid, title, rating, tags): url = d.absolutify_url('/submission/%s/%s' % (submitid, text.slug_for(title))) st = d.meta.tables['searchtag'] sms = d.meta.tables['searchmapsubmit'] q = (sa.select([st.c.title]) .select_from(st.join(sms, st.c.tagid == sms.c.tagid)) .where(st.c.title.in_(t.lower() for t in tags)) .group_by(st.c.title) .order_by(sa.func.count().desc())) account = 'WeasylCritique' if rating in (ratings.MATURE.code, ratings.EXPLICIT.code): account = 'WZLCritiqueNSFW' length = 26 selected_tags = [] db = d.connect() for tag, in db.execute(q): if len(tag) + 2 + length > 140: break selected_tags.append('#' + tag) length += len(tag) + 2 twits.post(account, u'%s %s' % (url, ' '.join(selected_tags)))
def select_view_api(userid, charid, anyway=False, increment_views=False): rating = define.get_rating(userid) query = _select_character_and_check( userid, charid, rating=rating, ignore=anyway, anyway=anyway, increment_views=increment_views) login = define.get_sysname(query['username']) return { 'charid': charid, 'owner': query['username'], 'owner_login': login, 'owner_media': api.tidy_all_media( media.get_user_media(query['userid'])), 'posted_at': define.iso8601(query['unixtime']), 'title': query['char_name'], 'age': query['age'], 'gender': query['gender'], 'height': query['height'], 'weight': query['weight'], 'species': query['species'], 'content': text.markdown(query['content']), 'rating': ratings.CODE_TO_NAME[query['rating']], 'favorited': favorite.check(userid, charid=charid), 'views': query['page_views'], 'friends_only': 'f' in query['settings'], 'favorites': favorite.count(charid, 'character'), 'comments': comment.count(charid, 'character'), 'media': api.tidy_all_media(fake_media_items( charid, query['userid'], login, query['settings'])), 'tags': searchtag.select(charid=charid), 'type': 'character', 'link': define.absolutify_url( '/character/%d/%s' % (charid, text.slug_for(query['char_name']))), }
def select_view_api(userid, submitid, anyway=False, increment_views=False): rating = d.get_rating(userid) db = d.connect() sub = db.query(orm.Submission).get(submitid) if sub is None or 'hidden' in sub.settings: raise WeasylError("submissionRecordMissing") sub_rating = sub.rating.code if 'friends-only' in sub.settings and not frienduser.check( userid, sub.userid): raise WeasylError("submissionRecordMissing") elif sub_rating > rating and userid != sub.userid: raise WeasylError("RatingExceeded") elif not anyway and ignoreuser.check(userid, sub.userid): raise WeasylError("UserIgnored") elif not anyway and blocktag.check(userid, submitid=submitid): raise WeasylError("TagBlocked") description = sub.content embedlink = None if 'embedded-content' in sub.settings: embedlink, _, description = description.partition('\n') elif 'gdocs-embed' in sub.settings: embedlink = sub.google_doc_embed.embed_url views = sub.page_views if increment_views and d.common_view_content(userid, submitid, 'submit'): views += 1 return { 'submitid': submitid, 'title': sub.title, 'owner': sub.owner.profile.username, 'owner_login': sub.owner.login_name, 'owner_media': api.tidy_all_media(media.get_user_media(sub.userid)), 'media': api.tidy_all_media(media.get_submission_media(submitid)), 'description': text.markdown(description), 'embedlink': embedlink, 'folderid': sub.folderid, 'folder_name': sub.folder.title if sub.folderid else None, 'posted_at': d.iso8601(sub.unixtime), 'tags': searchtag.select(submitid=submitid), 'link': d.absolutify_url("/submission/%d/%s" % (submitid, text.slug_for(sub.title))), 'type': 'submission', 'subtype': m.CATEGORY_PARSABLE_MAP[sub.subtype // 1000 * 1000], 'rating': sub.rating.name, 'views': views, 'favorites': favorite.count(submitid), 'comments': comment.count(submitid), 'favorited': favorite.check(userid, submitid=submitid), 'friends_only': 'friends-only' in sub.settings, }