docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
Return an instance of `cls` parsed from its `serialized` form.
Args:
cls: The :class:`OpaqueKey` subclass.
serialized (unicode): A serialized :class:`OpaqueKey`, with namespace already removed.
Raises:
InvalidKeyError: Should be raised if `serialized` is not a valid... | def _from_string(cls, serialized):
try:
usage_key, aside_type = _split_keys_v1(serialized)
return cls(UsageKey.from_string(usage_key), aside_type)
except ValueError as exc:
raise InvalidKeyError(cls, exc.args) | 499,748 |
Downloads zipped, tab-separated Biogrid data in .tab2 format.
Parameters:
-----------
url : str
URL of the BioGrid zip file.
Returns
-------
csv.reader
A csv.reader object for iterating over the rows (header has already
been skipped). | def _download_biogrid_data(url):
res = requests.get(biogrid_file_url)
if res.status_code != 200:
raise Exception('Unable to download Biogrid data: status code %s'
% res.status_code)
zip_bytes = BytesIO(res.content)
zip_file = ZipFile(zip_bytes)
zip_info_list = zi... | 500,905 |
Function to reverts a post to a previous version (Requires login).
Parameters:
post_id (int):
version_id (int): The post version id to revert to. | def post_revert(self, post_id, version_id):
return self._get('posts/{0}/revert.json'.format(post_id),
{'version_id': version_id}, 'PUT', auth=True) | 501,423 |
Function to copy notes (requires login).
Parameters:
post_id (int):
other_post_id (int): The id of the post to copy notes to. | def post_copy_notes(self, post_id, other_post_id):
return self._get('posts/{0}/copy_notes.json'.format(post_id),
{'other_post_id': other_post_id}, 'PUT', auth=True) | 501,424 |
Mark post as translated (Requires login) (UNTESTED).
If you set check_translation and partially_translated to 1 post will
be tagged as 'translated_request'
Parameters:
post_id (int):
check_translation (int): Can be 0, 1.
partially_translated (int): Can be 0,... | def post_mark_translated(self, post_id, check_translation,
partially_translated):
param = {
'post[check_translation]': check_translation,
'post[partially_translated]': partially_translated
}
return self._get('posts/{0}/mark_as_tra... | 501,425 |
Action lets you vote for a post (Requires login).
Danbooru: Post votes/create.
Parameters:
post_id (int):
score (str): Can be: up, down. | def post_vote(self, post_id, score):
return self._get('posts/{0}/votes.json'.format(post_id),
{'score': score}, 'POST', auth=True) | 501,426 |
Action lets you unvote for a post (Requires login).
Parameters:
post_id (int): | def post_unvote(self, post_id):
return self._get('posts/{0}/unvote.json'.format(post_id),
method='PUT', auth=True) | 501,427 |
Function to flag a post (Requires login).
Parameters:
creator_id (int): The user id of the flag's creator.
creator_name (str): The name of the flag's creator.
post_id (int): The post id if the flag. | def post_flag_list(self, creator_id=None, creator_name=None, post_id=None,
reason_matches=None, is_resolved=None, category=None):
params = {
'search[creator_id]': creator_id,
'search[creator_name]': creator_name,
'search[post_id]': post_id,
... | 501,428 |
Function to flag a post.
Parameters:
post_id (int): The id of the flagged post.
reason (str): The reason of the flagging. | def post_flag_create(self, post_id, reason):
params = {'post_flag[post_id]': post_id, 'post_flag[reason]': reason}
return self._get('post_flags.json', params, 'POST', auth=True) | 501,429 |
Function to return list of appeals (Requires login).
Parameters:
creator_id (int): The user id of the appeal's creator.
creator_name (str): The name of the appeal's creator.
post_id (int): The post id if the appeal. | def post_appeals_list(self, creator_id=None, creator_name=None,
post_id=None):
params = {
'creator_id': creator_id,
'creator_name': creator_name,
'post_id': post_id
}
return self._get('post_appeals.json', params, auth=Tru... | 501,430 |
Function to create appeals (Requires login).
Parameters:
post_id (int): The id of the appealed post.
reason (str) The reason of the appeal. | def post_appeals_create(self, post_id, reason):
params = {'post_appeal[post_id]': post_id,
'post_appeal[reason]': reason}
return self._get('post_appeals.json', params, 'POST', auth=True) | 501,431 |
Get list of post versions.
Parameters:
updater_name (str):
updater_id (int):
post_id (int):
start_id (int): | def post_versions_list(self, updater_name=None, updater_id=None,
post_id=None, start_id=None):
params = {
'search[updater_name]': updater_name,
'search[updater_id]': updater_id,
'search[post_id]': post_id,
'search[start_id]': st... | 501,432 |
Undo post version (Requires login) (UNTESTED).
Parameters:
version_id (int): | def post_versions_undo(self, version_id):
return self._get('post_versions/{0}/undo.json'.format(version_id),
method='PUT', auth=True) | 501,433 |
Search and return an uploads list (Requires login).
Parameters:
uploader_id (int): The id of the uploader.
uploader_name (str): The name of the uploader.
source (str): The source of the upload (exact string match). | def upload_list(self, uploader_id=None, uploader_name=None, source=None):
params = {
'search[uploader_id]': uploader_id,
'search[uploader_name]': uploader_name,
'search[source]': source
}
return self._get('uploads.json', params, auth=True) | 501,434 |
Action to lets you create a comment (Requires login).
Parameters:
post_id (int):
body (str):
do_not_bump_post (bool): Set to 1 if you do not want the post to be
bumped to the top of the comment listing. | def comment_create(self, post_id, body, do_not_bump_post=None):
params = {
'comment[post_id]': post_id,
'comment[body]': body,
'comment[do_not_bump_post]': do_not_bump_post
}
return self._get('comments.json', params, 'POST', auth=True) | 501,437 |
Function to update a comment (Requires login).
Parameters:
comment_id (int):
body (str): | def comment_update(self, comment_id, body):
params = {'comment[body]': body}
return self._get('comments/{0}.json'.format(comment_id), params, 'PUT',
auth=True) | 501,438 |
Remove a specific comment (Requires login).
Parameters:
comment_id (int): The id number of the comment to remove. | def comment_delete(self, comment_id):
return self._get('comments/{0}.json'.format(comment_id),
method='DELETE', auth=True) | 501,439 |
Undelete a specific comment (Requires login) (UNTESTED).
Parameters:
comment_id (int): | def comment_undelete(self, comment_id):
return self._get('comments/{0}/undelete.json'.format(comment_id),
method='POST', auth=True) | 501,440 |
Lets you vote for a comment (Requires login).
Parameters:
comment_id (int):
score (str): Can be: up, down. | def comment_vote(self, comment_id, score):
params = {'score': score}
return self._get('comments/{0}/votes.json'.format(comment_id), params,
method='POST', auth=True) | 501,441 |
Lets you unvote a specific comment (Requires login).
Parameters:
comment_id (int): | def comment_unvote(self, comment_id):
return self._get('posts/{0}/unvote.json'.format(comment_id),
method='POST', auth=True) | 501,442 |
Remove a post from favorites (Requires login).
Parameters:
post_id (int): Where post_id is the post id. | def favorite_remove(self, post_id):
return self._get('favorites/{0}.json'.format(post_id), method='DELETE',
auth=True) | 501,443 |
Return list of Dmails. You can only view dmails you own
(Requires login).
Parameters:
message_matches (str): The message body contains the given terms.
to_name (str): The recipient's name.
to_id (int): The recipient's user id.
from_name (str): The sender'... | def dmail_list(self, message_matches=None, to_name=None, to_id=None,
from_name=None, from_id=None, read=None):
params = {
'search[message_matches]': message_matches,
'search[to_name]': to_name,
'search[to_id]': to_id,
'search[from_name]... | 501,444 |
Create a dmail (Requires login)
Parameters:
to_name (str): The recipient's name.
title (str): The title of the message.
body (str): The body of the message. | def dmail_create(self, to_name, title, body):
params = {
'dmail[to_name]': to_name,
'dmail[title]': title,
'dmail[body]': body
}
return self._get('dmails.json', params, 'POST', auth=True) | 501,445 |
Delete a dmail. You can only delete dmails you own (Requires login).
Parameters:
dmail_id (int): where dmail_id is the dmail id. | def dmail_delete(self, dmail_id):
return self._get('dmails/{0}.json'.format(dmail_id), method='DELETE',
auth=True) | 501,446 |
Action to lets you delete an artist (Requires login) (UNTESTED)
(Only Builder+).
Parameters:
artist_id (int): Where artist_id is the artist id. | def artist_delete(self, artist_id):
return self._get('artists/{0}.json'.format(artist_id), method='DELETE',
auth=True) | 501,450 |
Lets you undelete artist (Requires login) (UNTESTED) (Only Builder+).
Parameters:
artist_id (int): | def artist_undelete(self, artist_id):
return self._get('artists/{0}/undelete.json'.format(artist_id),
method='POST', auth=True) | 501,451 |
Revert an artist (Requires login) (UNTESTED).
Parameters:
artist_id (int): The artist id.
version_id (int): The artist version id to revert to. | def artist_revert(self, artist_id, version_id):
params = {'version_id': version_id}
return self._get('artists/{0}/revert.json'.format(artist_id), params,
method='PUT', auth=True) | 501,452 |
Get list of artist versions (Requires login).
Parameters:
name (str):
updater_name (str):
updater_id (int):
artist_id (int):
is_active (bool): Can be: True, False.
is_banned (bool): Can be: True, False.
order (str): Can be: nam... | def artist_versions(self, name=None, updater_name=None, updater_id=None,
artist_id=None, is_active=None, is_banned=None,
order=None):
params = {
'search[name]': name,
'search[updater_name]': updater_name,
'search[update... | 501,453 |
list artist commentary.
Parameters:
text_matches (str):
post_id (int):
post_tags_match (str): The commentary's post's tags match the
giventerms. Meta-tags not supported.
original_present (str): Can be: yes, no.
trans... | def artist_commentary_list(self, text_matches=None, post_id=None,
post_tags_match=None, original_present=None,
translated_present=None):
params = {
'search[text_matches]': text_matches,
'search[post_id]': post_id,
... | 501,454 |
Create or update artist commentary (Requires login) (UNTESTED).
Parameters:
post_id (int): Post id.
original_title (str): Original title.
original_description (str): Original description.
translated_title (str): Translated title.
translated_descriptio... | def artist_commentary_create_update(self, post_id, original_title,
original_description, translated_title,
translated_description):
params = {
'artist_commentary[post_id]': post_id,
'artist_commentar... | 501,455 |
Revert artist commentary (Requires login) (UNTESTED).
Parameters:
id_ (int): The artist commentary id.
version_id (int): The artist commentary version id to
revert to. | def artist_commentary_revert(self, id_, version_id):
params = {'version_id': version_id}
return self._get('artist_commentaries/{0}/revert.json'.format(id_),
params, method='PUT', auth=True) | 501,456 |
Return list of artist commentary versions.
Parameters:
updater_id (int):
post_id (int): | def artist_commentary_versions(self, post_id, updater_id):
params = {'search[updater_id]': updater_id, 'search[post_id]': post_id}
return self._get('artist_commentary_versions.json', params) | 501,457 |
Return list of notes.
Parameters:
body_matches (str): The note's body matches the given terms.
post_id (int): A specific post.
post_tags_match (str): The note's post's tags match the given terms.
creator_name (str): The creator's name. Exact match.
cr... | def note_list(self, body_matches=None, post_id=None, post_tags_match=None,
creator_name=None, creator_id=None, is_active=None):
params = {
'search[body_matches]': body_matches,
'search[post_id]': post_id,
'search[post_tags_match]': post_tags_match,
... | 501,458 |
delete a specific note (Requires login) (UNTESTED).
Parameters:
note_id (int): Where note_id is the note id. | def note_delete(self, note_id):
return self._get('notes/{0}.json'.format(note_id), method='DELETE',
auth=True) | 501,461 |
Function to revert a specific note (Requires login) (UNTESTED).
Parameters:
note_id (int): Where note_id is the note id.
version_id (int): The note version id to revert to. | def note_revert(self, note_id, version_id):
return self._get('notes/{0}/revert.json'.format(note_id),
{'version_id': version_id}, method='PUT', auth=True) | 501,462 |
Get list of note versions.
Parameters:
updater_id (int):
post_id (int):
note_id (int): | def note_versions(self, updater_id=None, post_id=None, note_id=None):
params = {
'search[updater_id]': updater_id,
'search[post_id]': post_id,
'search[note_id]': note_id
}
return self._get('note_versions.json', params) | 501,463 |
Function to create a pool (Requires login) (UNTESTED).
Parameters:
name (str): Pool name.
description (str): Pool description.
category (str): Can be: series, collection. | def pool_create(self, name, description, category):
params = {
'pool[name]': name,
'pool[description]': description,
'pool[category]': category
}
return self._get('pools.json', params, method='POST', auth=True) | 501,466 |
Update a pool (Requires login) (UNTESTED).
Parameters:
pool_id (int): Where pool_id is the pool id.
name (str):
description (str):
post_ids (str): List of space delimited post ids.
is_active (int): Can be: 1, 0.
category (str): Can be: ser... | def pool_update(self, pool_id, name=None, description=None, post_ids=None,
is_active=None, category=None):
params = {
'pool[name]': name,
'pool[description]': description,
'pool[post_ids]': post_ids,
'pool[is_active]': is_active,
... | 501,467 |
Delete a pool (Requires login) (UNTESTED) (Moderator+).
Parameters:
pool_id (int): Where pool_id is the pool id. | def pool_delete(self, pool_id):
return self._get('pools/{0}.json'.format(pool_id), method='DELETE',
auth=True) | 501,468 |
Undelete a specific poool (Requires login) (UNTESTED) (Moderator+).
Parameters:
pool_id (int): Where pool_id is the pool id. | def pool_undelete(self, pool_id):
return self._get('pools/{0}/undelete.json'.format(pool_id),
method='POST', auth=True) | 501,469 |
Function to revert a specific pool (Requires login) (UNTESTED).
Parameters:
pool_id (int): Where pool_id is the pool id.
version_id (int): | def pool_revert(self, pool_id, version_id):
return self._get('pools/{0}/revert.json'.format(pool_id),
{'version_id': version_id}, method='PUT', auth=True) | 501,470 |
Get list of pool versions.
Parameters:
updater_id (int):
updater_name (str):
pool_id (int): | def pool_versions(self, updater_id=None, updater_name=None, pool_id=None):
params = {
'search[updater_id]': updater_id,
'search[updater_name]': updater_name,
'search[pool_id]': pool_id
}
return self._get('pool_versions.json', params) | 501,471 |
Lets you update a tag (Requires login) (UNTESTED).
Parameters:
tag_id (int):
category (str): Can be: 0, 1, 3, 4 (general, artist, copyright,
character respectively). | def tag_update(self, tag_id, category):
param = {'tag[category]': category}
return self._get('pools/{0}.json'.format(tag_id), param, method='PUT',
auth=True) | 501,473 |
Get tags aliases.
Parameters:
name_matches (str): Match antecedent or consequent name.
antecedent_name (str): Match antecedent name (exact match).
tag_id (int): The tag alias id. | def tag_aliases(self, name_matches=None, antecedent_name=None,
tag_id=None):
params = {
'search[name_matches]': name_matches,
'search[antecedent_name]': antecedent_name,
'search[id]': tag_id
}
return self._get('tag_aliases.json... | 501,474 |
Get tags implications.
Parameters:
name_matches (str): Match antecedent or consequent name.
antecedent_name (str): Match antecedent name (exact match).
tag_id (int): Tag implication id. | def tag_implications(self, name_matches=None, antecedent_name=None,
tag_id=None):
params = {
'search[name_matches]': name_matches,
'search[antecedent_name]': antecedent_name,
'search[id]': tag_id
}
return self._get('tag_im... | 501,475 |
Get related tags.
Parameters:
query (str): The tag to find the related tags for.
category (str): If specified, show only tags of a specific
category. Can be: General 0, Artist 1, Copyright
3 and Character 4. | def tag_related(self, query, category=None):
params = {'query': query, 'category': category}
return self._get('related_tag.json', params) | 501,476 |
Function to retrieves a list of every wiki page.
Parameters:
title (str): Page title.
creator_id (int): Creator id.
body_matches (str): Page content.
other_names_match (str): Other names.
creator_name (str): Creator name.
hide_deleted (str... | def wiki_list(self, title=None, creator_id=None, body_matches=None,
other_names_match=None, creator_name=None, hide_deleted=None,
other_names_present=None, order=None):
params = {
'search[title]': title,
'search[creator_id]': creator_id,
... | 501,477 |
Action to lets you create a wiki page (Requires login) (UNTESTED).
Parameters:
title (str): Page title.
body (str): Page content.
other_names (str): Other names. | def wiki_create(self, title, body, other_names=None):
params = {
'wiki_page[title]': title,
'wiki_page[body]': body,
'wiki_page[other_names]': other_names
}
return self._get('wiki_pages.json', params, method='POST', auth=True) | 501,478 |
Action to lets you update a wiki page (Requires login) (UNTESTED).
Parameters:
page_id (int): Whre page_id is the wiki page id.
title (str): Page title.
body (str): Page content.
other_names (str): Other names.
is_locked (int): Can be: 0, 1 (Builder+)... | def wiki_update(self, page_id, title=None, body=None,
other_names=None, is_locked=None, is_deleted=None):
params = {
'wiki_page[title]': title,
'wiki_page[body]': body,
'wiki_page[other_names]': other_names
}
return self._get('... | 501,479 |
Delete a specific page wiki (Requires login) (UNTESTED) (Builder+).
Parameters:
page_id (int): | def wiki_delete(self, page_id):
return self._get('wiki_pages/{0}.json'.format(page_id), auth=True,
method='DELETE') | 501,480 |
Revert page to a previeous version (Requires login) (UNTESTED).
Parameters:
wiki_page_id (int): Where page_id is the wiki page id.
version_id (int): | def wiki_revert(self, wiki_page_id, version_id):
return self._get('wiki_pages/{0}/revert.json'.format(wiki_page_id),
{'version_id': version_id}, method='PUT', auth=True) | 501,481 |
Return a list of wiki page version.
Parameters:
page_id (int):
updater_id (int): | def wiki_versions_list(self, page_id, updater_id):
params = {
'earch[updater_id]': updater_id,
'search[wiki_page_id]': page_id
}
return self._get('wiki_page_versions.json', params) | 501,482 |
Function to get forum topics.
Parameters:
title_matches (str): Search body for the given terms.
title (str): Exact title match.
category_id (int): Can be: 0, 1, 2 (General, Tags, Bugs & Features
respectively). | def forum_topic_list(self, title_matches=None, title=None,
category_id=None):
params = {
'search[title_matches]': title_matches,
'search[title]': title,
'search[category_id]': category_id
}
return self._get('forum_topics.j... | 501,483 |
Function to create topic (Requires login) (UNTESTED).
Parameters:
title (str): topic title.
body (str): Message of the initial post.
category (str): Can be: 0, 1, 2 (General, Tags, Bugs & Features
respectively). | def forum_topic_create(self, title, body, category=None):
params = {
'forum_topic[title]': title,
'forum_topic[original_post_attributes][body]': body,
'forum_topic[category_id]': category
}
return self._get('forum_topics.json', params, method='POS... | 501,484 |
Update a specific topic (Login Requires) (UNTESTED).
Parameters:
topic_id (int): Where topic_id is the topic id.
title (str): Topic title.
category (str): Can be: 0, 1, 2 (General, Tags, Bugs & Features
respectively). | def forum_topic_update(self, topic_id, title=None, category=None):
params = {
'forum_topic[title]': title,
'forum_topic[category_id]': category
}
return self._get('forum_topics/{0}.json'.format(topic_id), params,
method='PUT', auth=Tr... | 501,485 |
Delete a topic (Login Requires) (Moderator+) (UNTESTED).
Parameters:
topic_id (int): Where topic_id is the topic id. | def forum_topic_delete(self, topic_id):
return self._get('forum_topics/{0}.json'.format(topic_id),
method='DELETE', auth=True) | 501,486 |
Un delete a topic (Login requries) (Moderator+) (UNTESTED).
Parameters:
topic_id (int): Where topic_id is the topic id. | def forum_topic_undelete(self, topic_id):
return self._get('forum_topics/{0}/undelete.json'.format(topic_id),
method='POST', auth=True) | 501,487 |
Return a list of forum posts.
Parameters:
creator_id (int):
creator_name (str):
topic_id (int):
topic_title_matches (str):
topic_category_id (int): Can be: 0, 1, 2 (General, Tags, Bugs &
Features respectively).
... | def forum_post_list(self, creator_id=None, creator_name=None,
topic_id=None, topic_title_matches=None,
topic_category_id=None, body_matches=None):
params = {
'search[creator_id]': creator_id,
'search[creator_name]': creator_name,
... | 501,488 |
Create a forum post (Requires login).
Parameters:
topic_id (int):
body (str): Post content. | def forum_post_create(self, topic_id, body):
params = {'forum_post[topic_id]': topic_id, 'forum_post[body]': body}
return self._get('forum_posts.json', params, method='POST', auth=True) | 501,489 |
Update a specific forum post (Requries login)(Moderator+)(UNTESTED).
Parameters:
post_id (int): Forum topic id.
body (str): Post content. | def forum_post_update(self, topic_id, body):
params = {'forum_post[body]': body}
return self._get('forum_posts/{0}.json'.format(topic_id), params,
method='PUT', auth=True) | 501,490 |
Delete a specific forum post (Requires login)(Moderator+)(UNTESTED).
Parameters:
post_id (int): Forum post id. | def forum_post_delete(self, post_id):
return self._get('forum_posts/{0}.json'.format(post_id),
method='DELETE', auth=True) | 501,491 |
Undelete a specific forum post (Requires login)(Moderator+)(UNTESTED).
Parameters:
post_id (int): Forum post id. | def forum_post_undelete(self, post_id):
return self._get('forum_posts/{0}/undelete.json'.format(post_id),
method='POST', auth=True) | 501,492 |
Function that sets and checks the site name and set url.
Parameters:
site_name (str): The site name in 'SITE_LIST', default sites.
Raises:
PybooruError: When 'site_name' isn't valid. | def site_name(self, site_name):
if site_name in SITE_LIST:
self.__site_name = site_name
self.__site_url = SITE_LIST[site_name]['url']
else:
raise PybooruError(
"The 'site_name' is not valid, specify a valid 'site_name'.") | 501,496 |
URL setter and validator for site_url property.
Parameters:
url (str): URL of on Moebooru/Danbooru based sites.
Raises:
PybooruError: When URL scheme or URL are invalid. | def site_url(self, url):
# Regular expression to URL validate
regex = re.compile(
r'^(?:http|https)://' # Scheme only HTTP/HTTPS
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?| \
[A-Z0-9-]{2,}(?<!-)\.?)|' # Domain
r'localhost|'... | 501,497 |
Function to request and returning JSON data.
Parameters:
url (str): Base url call.
api_call (str): API function to be called.
request_args (dict): All requests parameters.
method (str): (Defauld: GET) HTTP method 'GET' or 'POST'
Raises:
Pyboo... | def _request(self, url, api_call, request_args, method='GET'):
try:
if method != 'GET':
# Reset content-type for data encoded as a multipart form
self.client.headers.update({'content-type': None})
response = self.client.request(method, url, **req... | 501,498 |
Function to preapre API call.
Parameters:
api_call (str): API function to be called.
params (str): API function parameters.
method (str): (Defauld: GET) HTTP method (GET, POST, PUT or
DELETE)
file_ (file): File to upload (only uploads).... | def _get(self, api_call, params=None, method='GET', auth=False,
file_=None):
url = "{0}/{1}".format(self.site_url, api_call)
if method == 'GET':
request_args = {'params': params}
else:
request_args = {'data': params, 'files': file_}
# Adds ... | 501,500 |
Function to reverts a post to a previous set of tags
(Requires login) (UNTESTED).
Parameters:
post_id (int): The post id number to update.
history_id (int): The id number of the tag history. | def post_revert_tags(self, post_id, history_id):
params = {'id': post_id, 'history_id': history_id}
return self._get('post/revert_tags', params, 'PUT') | 501,503 |
Action lets you vote for a post (Requires login).
Parameters:
post_id (int): The post id.
score (int):
* 0: No voted or Remove vote.
* 1: Good.
* 2: Great.
* 3: Favorite, add post to favorites.
Raises:
... | def post_vote(self, post_id, score):
if score <= 3 and score >= 0:
params = {'id': post_id, 'score': score}
return self._get('post/vote', params, 'POST')
else:
raise PybooruAPIError("Value of 'score' only can be 0, 1, 2 or 3.") | 501,504 |
Action to lets you update tag (Requires login) (UNTESTED).
Parameters:
name (str): The name of the tag to update.
tag_type (int):
* General: 0.
* artist: 1.
* copyright: 3.
* character: 4.
is_ambiguous (int): Wh... | def tag_update(self, name=None, tag_type=None, is_ambiguous=None):
params = {
'name': name,
'tag[tag_type]': tag_type,
'tag[is_ambiguous]': is_ambiguous
}
return self._get('tag/update', params, 'PUT') | 501,505 |
Action to lets you create a comment (Requires login).
Parameters:
post_id (int): The post id number to which you are responding.
comment_body (str): The body of the comment.
anonymous (int): Set to 1 if you want to post this comment
anonymously. | def comment_create(self, post_id, comment_body, anonymous=None):
params = {
'comment[post_id]': post_id,
'comment[body]': comment_body,
'comment[anonymous]': anonymous
}
return self._get('comment/create', params, method='POST') | 501,508 |
Action to lets you create a wiki page (Requires login) (UNTESTED).
Parameters:
title (str): The title of the wiki page.
body (str): The body of the wiki page. | def wiki_create(self, title, body):
params = {'wiki_page[title]': title, 'wiki_page[body]': body}
return self._get('wiki/create', params, method='POST') | 501,509 |
Action to lets you update a wiki page (Requires login) (UNTESTED).
Parameters:
title (str): The title of the wiki page to update.
new_title (str): The new title of the wiki page.
page_body (str): The new body of the wiki page. | def wiki_update(self, title, new_title=None, page_body=None):
params = {
'title': title,
'wiki_page[title]': new_title,
'wiki_page[body]': page_body
}
return self._get('wiki/update', params, method='PUT') | 501,510 |
Function to revert a specific wiki page (Requires login) (UNTESTED).
Parameters:
title (str): The title of the wiki page to update.
version (int): The version to revert to. | def wiki_revert(self, title, version):
params = {'title': title, 'version': version}
return self._get('wiki/revert', params, method='PUT') | 501,511 |
Function to revert a specific note (Requires login) (UNTESTED).
Parameters:
note_id (int): The note id to update.
version (int): The version to revert to. | def note_revert(self, note_id, version):
params = {'id': note_id, 'version': version}
return self._get('note/revert', params, method='PUT') | 501,512 |
Function to update a pool (Requires login) (UNTESTED).
Parameters:
pool_id (int): The pool id number.
name (str): The name.
is_public (int): 1 or 0, whether or not the pool is public.
description (str): A description of the pool. | def pool_update(self, pool_id, name=None, is_public=None,
description=None):
params = {
'id': pool_id,
'pool[name]': name,
'pool[is_public]': is_public,
'pool[description]': description
}
return self._get('pool/upda... | 501,514 |
Function to create a pool (Require login) (UNTESTED).
Parameters:
name (str): The name.
description (str): A description of the pool.
is_public (int): 1 or 0, whether or not the pool is public. | def pool_create(self, name, description, is_public):
params = {'pool[name]': name, 'pool[description]': description,
'pool[is_public]': is_public}
return self._get('pool/create', params, method='POST') | 501,515 |
Sets api_version and hash_string.
Parameters:
site_name (str): The site name in 'SITE_LIST', default sites.
Raises:
PybooruError: When 'site_name' isn't valid. | def site_name(self, site_name):
# Set base class property site_name
_Pybooru.site_name.fset(self, site_name)
if ('api_version' and 'hashed_string') in SITE_LIST[site_name]:
self.api_version = SITE_LIST[site_name]['api_version']
self.hash_string = SITE_LIST[site_... | 501,517 |
Build request url.
Parameters:
api_call (str): Base API Call.
Returns:
Complete url (str). | def _build_url(self, api_call):
if self.api_version in ('1.13.0', '1.13.0+update.1', '1.13.0+update.2'):
if '/' not in api_call:
return "{0}/{1}/index.json".format(self.site_url, api_call)
return "{0}/{1}.json".format(self.site_url, api_call) | 501,518 |
Function to preapre API call.
Parameters:
api_call (str): API function to be called.
params (dict): API function parameters.
method (str): (Defauld: GET) HTTP method 'GET' or 'POST'
file_ (file): File to upload. | def _get(self, api_call, params, method='GET', file_=None):
url = self._build_url(api_call)
if method == 'GET':
request_args = {'params': params}
else:
if self.password_hash is None:
self._build_hash_string()
# Set login
... | 501,520 |
Converts an iterator of edges to an adjacency dict.
Args:
edgelist (iterable):
An iterator over 2-tuples where each 2-tuple is an edge.
Returns:
dict: The adjacency dict. A dict of the form {v: Nv, ...} where v is a node in a graph and
Nv is the neighbors of v as an set. | def edgelist_to_adjacency(edgelist):
adjacency = dict()
for u, v in edgelist:
if u in adjacency:
adjacency[u].add(v)
else:
adjacency[u] = {v}
if v in adjacency:
adjacency[v].add(u)
else:
adjacency[v] = {u}
return adjacency | 501,987 |
Returns a connection object to a sqlite database.
Args:
database (str, optional): The path to the database the user wishes
to connect to. If not specified, a default is chosen using
:func:`.cache_file`. If the special database name ':memory:'
is given, then a temporary d... | def cache_connect(database=None):
if database is None:
database = cache_file()
if os.path.isfile(database):
# just connect to the database as-is
conn = sqlite3.connect(database)
else:
# we need to populate the database
conn = sqlite3.connect(database)
co... | 501,990 |
Iterate over all of the chains in the database.
Args:
cur (:class:`sqlite3.Cursor`):
An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.
Yields:
list: The chain. | def iter_chain(cur):
select = "SELECT nodes FROM chain"
for nodes, in cur.execute(select):
yield json.loads(nodes) | 501,992 |
Insert a system name into the cache.
Args:
cur (:class:`sqlite3.Cursor`):
An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.
system_name (str):
The unique name of a system
encoded_data (dict, optional):
If a dictionary i... | def insert_system(cur, system_name, encoded_data=None):
if encoded_data is None:
encoded_data = {}
if 'system_name' not in encoded_data:
encoded_data['system_name'] = system_name
insert = "INSERT OR IGNORE INTO system(system_name) VALUES (:system_name);"
cur.execute(insert, encode... | 501,993 |
Iterate over all flux biases in the cache.
Args:
cur (:class:`sqlite3.Cursor`):
An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.
Yields:
tuple: A 4-tuple:
list: The chain.
str: The system name.
float: The flu... | def iter_flux_bias(cur):
select = \
for nodes, system, flux_bias, chain_strength in cur.execute(select):
yield json.loads(nodes), system, _decode_real(flux_bias), _decode_real(chain_strength) | 501,995 |
Validate the provided chain strength, checking J-ranges of the sampler's children.
Args:
chain_strength (float) The provided chain strength. Use None to use J-range.
Returns (float):
A valid chain strength, either provided or based on available J-range. Positive finite float. | def _validate_chain_strength(sampler, chain_strength):
properties = sampler.properties
if 'extended_j_range' in properties:
max_chain_strength = - min(properties['extended_j_range'])
elif 'j_range' in properties:
max_chain_strength = - min(properties['j_range'])
else:
raise... | 502,061 |
A simple (bool) diagnostic for minor embeddings.
See :func:`diagnose_embedding` for a more detailed diagnostic / more information.
Args:
emb (dict): a dictionary mapping source nodes to arrays of target nodes
source (graph or edgelist): the graph to be embedded
target (graph or edgelis... | def is_valid_embedding(emb, source, target):
for _ in diagnose_embedding(emb, source, target):
return False
return True | 502,081 |
This is method for replace operation. It is separated to provide a
possibility to easily override it in your Parameters.
Args:
obj (object): an instance to change.
field (str): field name
value (str): new value
state (dict): inter-operations state storage... | def replace(cls, obj, field, value, state):
if not hasattr(obj, field):
raise ValidationError("Field '%s' does not exist, so it cannot be patched" % field)
setattr(obj, field, value)
return True | 502,161 |
This is method for test operation. It is separated to provide a
possibility to easily override it in your Parameters.
Args:
obj (object): an instance to change.
field (str): field name
value (str): new value
state (dict): inter-operations state storage
... | def test(cls, obj, field, value, state):
return getattr(obj, field) == value | 502,162 |
Create a magic packet.
A magic packet is a packet that can be used with the for wake on lan
protocol to wake up a computer. The packet is constructed from the
mac address given as a parameter.
Args:
macaddress (str): the mac address that should be parsed into a
magic packet. | def create_magic_packet(macaddress):
if len(macaddress) == 12:
pass
elif len(macaddress) == 17:
sep = macaddress[2]
macaddress = macaddress.replace(sep, '')
else:
raise ValueError('Incorrect MAC address format')
# Pad the synchronization stream
data = b'FFFFFFFF... | 502,546 |
Wake up computers having any of the given mac addresses.
Wake on lan must be enabled on the host device.
Args:
macs (str): One or more macaddresses of machines to wake.
Keyword Args:
ip_address (str): the ip address of the host to send the magic packet
to (default "25... | def send_magic_packet(*macs, **kwargs):
packets = []
ip = kwargs.pop('ip_address', BROADCAST_IP)
port = kwargs.pop('port', DEFAULT_PORT)
for k in kwargs:
raise TypeError('send_magic_packet() got an unexpected keyword '
'argument {!r}'.format(k))
for mac in macs:... | 502,547 |
Checks if there are multiple alternative alleles and splitts the
variant.
If there are multiple alternatives the info fields, vep annotations
and genotype calls will be splitted in the correct way
Args:
variant_dict: a dictionary with the variant information
Yields:
varia... | def split_variants(variant_dict, header_parser, allele_symbol='0'):
logger = getLogger(__name__)
logger.info("Allele symbol {0}".format(allele_symbol))
alternatives = variant_dict['ALT'].split(',')
reference = variant_dict['REF']
number_of_values = 1
# Go through each of the alternative all... | 502,692 |
Take a list with annotated rank scores for each family and returns a
dictionary with family_id as key and a list of genetic models as value.
Args:
rank_scores : A list on the form ['1:12','2:20']
Returns:
scores : A dictionary with family id:s as key and scores as value
... | def build_rank_score_dict(rank_scores):
logger = getLogger(__name__)
logger.debug("Checking rank scores: {0}".format(rank_scores))
scores = {}
for family in rank_scores:
entry = family.split(':')
try:
family_id = entry[0]
logger.debug("Extracting rank score f... | 502,693 |
Check if the info annotation corresponds to the metadata specification
Arguments:
annotation (list): The annotation from the vcf file
info (str): Name of the info field
extra_info (dict): The metadata specification
alternatives (list): A list with the alternative variants
... | def check_info_annotation(annotation, info, extra_info, alternatives, individuals=[]):
number = extra_info['Number']
if is_number(number):
number_of_entrys = float(number)
if number_of_entrys != 0:
if len(annotation) != number_of_entrys:
raise SyntaxError("I... | 502,694 |
Build a new vcf INFO string based on the information in the info_dict.
The info is a dictionary with vcf info keys as keys and lists of vcf values
as values. If there is no value False is value in info
Args:
info (dict): A dictionary with information from the vcf file
Returns:
... | def build_info_string(info):
info_list = []
for annotation in info:
if info[annotation]:
info_list.append('='.join([annotation, ','.join(info[annotation])]))
else:
info_list.append(annotation)
return ';'.join(info_list) | 502,696 |
Build a dictionary from the info of a vcf line
The dictionary will have the info keys as keys and info values as values.
Values will allways be lists that are splitted on ','
Arguments:
vcf_info (str): A string with vcf info
Returns:
info_dict (OrderedDict): A ordered dict... | def build_info_dict(vcf_info):
logger = logging.getLogger(__name__)
logger.debug("Building info dict")
info_dict = OrderedDict()
for info in vcf_info.split(';'):
info = info.split('=')
if len(info) > 1:
# If the INFO entry is like key=value, we store the value as a ... | 502,697 |
Add an info line to the header.
Arguments:
info_id (str): The id of the info line
number (str): Integer or any of [A,R,G,.]
entry_type (str): Any of [Integer,Float,Flag,Character,String]
description (str): A description of the info line | def add_info(self, info_id, number, entry_type, description):
info_line = '##INFO=<ID={0},Number={1},Type={2},Description="{3}">'.format(
info_id, number, entry_type, description
)
self.logger.info("Adding info line to vcf: {0}".format(info_line))
self.parse_meta_dat... | 502,702 |
Add a line with information about which software that was run and when
to the header.
Arguments:
info_id (str): The id of the info line
version (str): The version of the software used
date (str): Date when software was run
command_line (str): The... | def add_version_tracking(self, info_id, version, date, command_line=''):
other_line = '##Software=<ID={0},Version={1},Date="{2}",CommandLineOptions="{3}">'.format(
info_id, version, date, command_line)
self.other_dict[info_id] = other_line
return | 502,703 |
Build a vep string formatted string.
Take a list with vep annotations and build a new vep string
Args:
vep_info (list): A list with vep annotation dictionaries
vep_columns (list): A list with the vep column names found in the
header of the vcf
Returns:
string: ... | def build_vep_string(vep_info, vep_columns):
logger = getLogger(__name__)
logger.debug("Building vep string from {0}".format(vep_info))
logger.debug("Found vep headers {0}".format(vep_columns))
vep_strings = []
for vep_annotation in vep_info:
try:
vep_info_list = [
... | 502,711 |
Gets XBlock-specific settigns for current XBlock
Returns default if settings service is not available.
Parameters:
default - default value to be used in two cases:
* No settings service is available
* As a `default` parameter to `SettingsService.... | def get_xblock_settings(self, default=None):
settings_service = self.runtime.service(self, "settings")
if settings_service:
return settings_service.get_settings_bucket(self, default=default)
return default | 503,609 |
Create an instance whose attributes come from new_fields_dict and fallback_obj.
Arguments:
new_fields_dict -- A dictionary of values that will appear as attributes of this object
newly_removed_fields -- A list of field names for which we will not use fallback_obj
fallback_obj -- An XBlo... | def __init__(self, new_fields_dict, newly_removed_fields, fallback_obj):
self._new_fields_dict = new_fields_dict
self._blacklist = newly_removed_fields
self._fallback_obj = fallback_obj | 503,620 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.