_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q9300 | Network.getWord | train | def getWord(self, pattern, returnDiff = 0):
"""
Returns the word associated with pattern.
Example: net.getWord([0, 0, 0, 1]) => "tom"
This method now returns the closest pattern based on distance.
"""
minDist = 10000
closest = None
for w in self.patterns... | python | {
"resource": ""
} |
q9301 | Network.addPattern | train | def addPattern(self, word, vector):
"""
Adds a pattern with key word.
Example: net.addPattern("tom", [0, 0, 0, 1])
"""
if word in self.patterns:
raise NetworkError('Pattern key already in use. Call delPattern to free key.', word)
else:
se... | python | {
"resource": ""
} |
q9302 | Network.compare | train | def compare(self, v1, v2):
"""
Compares two values. Returns 1 if all values are withing
self.tolerance of each other.
"""
try:
if len(v1) != len(v2): return 0
for x, y in zip(v1, v2):
if abs( x - y ) > self.tolerance:
re... | python | {
"resource": ""
} |
q9303 | Network.shareWeights | train | def shareWeights(self, network, listOfLayerNamePairs = None):
"""
Share weights with another network. Connection
is broken after a randomize or change of size. Layers must have the same
names and sizes for shared connections in both networks.
Example: net.shareWeights(otherNet, ... | python | {
"resource": ""
} |
q9304 | BackpropNetwork.propagate | train | def propagate(self, *arg, **kw):
""" Propagates activation through the network."""
output = Network.propagate(self, *arg, **kw)
if self.interactive:
self.updateGraphics()
# IMPORTANT: convert results from numpy.floats to conventional floats
if type(output) == dict:
... | python | {
"resource": ""
} |
q9305 | BackpropNetwork.loadWeightsFromFile | train | def loadWeightsFromFile(self, filename, mode='pickle'):
"""
Deprecated. Use loadWeights instead.
"""
Network.loadWeights(self, filename, mode)
self.updateGraphics() | python | {
"resource": ""
} |
q9306 | SRN.setSequenceType | train | def setSequenceType(self, value):
"""
You must set this!
"""
if value == "ordered-continuous":
self.orderedInputs = 1
self.initContext = 0
elif value == "random-segmented":
self.orderedInputs = 0
self.initCon... | python | {
"resource": ""
} |
q9307 | SRN.addThreeLayers | train | def addThreeLayers(self, inc, hidc, outc):
"""
Creates a three level network with a context layer.
"""
self.addLayer('input', inc)
self.addContextLayer('context', hidc, 'hidden')
self.addLayer('hidden', hidc)
self.addLayer('output', outc)
self.connect('inp... | python | {
"resource": ""
} |
q9308 | SRN.addContext | train | def addContext(self, layer, hiddenLayerName = 'hidden', verbosity = 0):
"""
Adds a context layer. Necessary to keep self.contextLayers dictionary up to date.
"""
# better not add context layer first if using sweep() without mapInput
SRN.add(self, layer, verbosity)
if hid... | python | {
"resource": ""
} |
q9309 | SRN.copyHiddenToContext | train | def copyHiddenToContext(self):
"""
Uses key to identify the hidden layer associated with each
layer in the self.contextLayers dictionary.
"""
for item in list(self.contextLayers.items()):
if self.verbosity > 2: print('Hidden layer: ', self.getLayer(item[0]).activatio... | python | {
"resource": ""
} |
q9310 | Tokenizer.parse | train | def parse(self, line):
"""Tokenize a line of Fortran source."""
tokens = []
self.idx = -1 # Bogus value to ensure idx = 0 after first iteration
self.characters = iter(line)
self.update_chars()
while self.char != '\n':
# Update namelist group status
... | python | {
"resource": ""
} |
q9311 | Tokenizer.parse_name | train | def parse_name(self, line):
"""Tokenize a Fortran name, such as a variable or subroutine."""
end = self.idx
for char in line[self.idx:]:
if not char.isalnum() and char not in '\'"_':
break
end += 1
word = line[self.idx:end]
self.idx = end... | python | {
"resource": ""
} |
q9312 | Tokenizer.parse_string | train | def parse_string(self):
"""Tokenize a Fortran string."""
word = ''
if self.prior_delim:
delim = self.prior_delim
self.prior_delim = None
else:
delim = self.char
word += self.char
self.update_chars()
while True:
... | python | {
"resource": ""
} |
q9313 | Tokenizer.parse_numeric | train | def parse_numeric(self):
"""Tokenize a Fortran numerical value."""
word = ''
frac = False
if self.char == '-':
word += self.char
self.update_chars()
while self.char.isdigit() or (self.char == '.' and not frac):
# Only allow one decimal point
... | python | {
"resource": ""
} |
q9314 | Tokenizer.update_chars | train | def update_chars(self):
"""Update the current charters in the tokenizer."""
# NOTE: We spoof non-Unix files by returning '\n' on StopIteration
self.prior_char, self.char = self.char, next(self.characters, '\n')
self.idx += 1 | python | {
"resource": ""
} |
q9315 | pycomplex | train | def pycomplex(v_str):
"""Convert string repr of Fortran complex to Python complex."""
assert isinstance(v_str, str)
if v_str[0] == '(' and v_str[-1] == ')' and len(v_str.split(',')) == 2:
v_re, v_im = v_str[1:-1].split(',', 1)
# NOTE: Failed float(str) will raise ValueError
return ... | python | {
"resource": ""
} |
q9316 | pybool | train | def pybool(v_str, strict_logical=True):
"""Convert string repr of Fortran logical to Python logical."""
assert isinstance(v_str, str)
assert isinstance(strict_logical, bool)
if strict_logical:
v_bool = v_str.lower()
else:
try:
if v_str.startswith('.'):
v_... | python | {
"resource": ""
} |
q9317 | pystr | train | def pystr(v_str):
"""Convert string repr of Fortran string to Python string."""
assert isinstance(v_str, str)
if v_str[0] in ("'", '"') and v_str[0] == v_str[-1]:
quote = v_str[0]
out = v_str[1:-1]
else:
# NOTE: This is non-standard Fortran.
# For example, gfortran... | python | {
"resource": ""
} |
q9318 | pad_array | train | def pad_array(v, idx):
"""Expand lists in multidimensional arrays to pad unset values."""
i_v, i_s = idx[0]
if len(idx) > 1:
# Append missing subarrays
v.extend([[] for _ in range(len(v), i_v - i_s + 1)])
# Pad elements
for e in v:
pad_array(e, idx[1:])
else... | python | {
"resource": ""
} |
q9319 | merge_values | train | def merge_values(src, new):
"""Merge two lists or dicts into a single element."""
if isinstance(src, dict) and isinstance(new, dict):
return merge_dicts(src, new)
else:
if not isinstance(src, list):
src = [src]
if not isinstance(new, list):
new = [new]
... | python | {
"resource": ""
} |
q9320 | merge_lists | train | def merge_lists(src, new):
"""Update a value list with a list of new or updated values."""
l_min, l_max = (src, new) if len(src) < len(new) else (new, src)
l_min.extend(None for i in range(len(l_min), len(l_max)))
for i, val in enumerate(new):
if isinstance(val, dict) and isinstance(src[i], di... | python | {
"resource": ""
} |
q9321 | merge_dicts | train | def merge_dicts(src, patch):
"""Merge contents of dict `patch` into `src`."""
for key in patch:
if key in src:
if isinstance(src[key], dict) and isinstance(patch[key], dict):
merge_dicts(src[key], patch[key])
else:
src[key] = merge_values(src[key],... | python | {
"resource": ""
} |
q9322 | delist | train | def delist(values):
"""Reduce lists of zero or one elements to individual values."""
assert isinstance(values, list)
if not values:
return None
elif len(values) == 1:
return values[0]
return values | python | {
"resource": ""
} |
q9323 | count_values | train | def count_values(tokens):
"""Identify the number of values ahead of the current token."""
ntoks = 0
for tok in tokens:
if tok in ('=', '/', '$', '&'):
if ntoks > 0 and tok == '=':
ntoks -= 1
break
elif tok in whitespace + ',':
continue
... | python | {
"resource": ""
} |
q9324 | Parser.comment_tokens | train | def comment_tokens(self, value):
"""Validate and set the comment token string."""
if not isinstance(value, str):
raise TypeError('comment_tokens attribute must be a string.')
self._comment_tokens = value | python | {
"resource": ""
} |
q9325 | Parser.default_start_index | train | def default_start_index(self, value):
"""Validate and set the default start index."""
if not isinstance(value, int):
raise TypeError('default_start_index attribute must be of int '
'type.')
self._default_start_index = value | python | {
"resource": ""
} |
q9326 | Parser.sparse_arrays | train | def sparse_arrays(self, value):
"""Validate and enable spare arrays."""
if not isinstance(value, bool):
raise TypeError('sparse_arrays attribute must be a logical type.')
self._sparse_arrays = value | python | {
"resource": ""
} |
q9327 | Parser.global_start_index | train | def global_start_index(self, value):
"""Set the global start index."""
if not isinstance(value, int) and value is not None:
raise TypeError('global_start_index attribute must be of int '
'type.')
self._global_start_index = value | python | {
"resource": ""
} |
q9328 | Parser.row_major | train | def row_major(self, value):
"""Validate and set row-major format for multidimensional arrays."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: row_major must be a logical value.')
else:
s... | python | {
"resource": ""
} |
q9329 | Parser.strict_logical | train | def strict_logical(self, value):
"""Validate and set the strict logical flag."""
if value is not None:
if not isinstance(value, bool):
raise TypeError(
'f90nml: error: strict_logical must be a logical value.')
else:
self._strict... | python | {
"resource": ""
} |
q9330 | Parser.read | train | def read(self, nml_fname, nml_patch_in=None, patch_fname=None):
"""Parse a Fortran namelist file and store the contents.
>>> parser = f90nml.Parser()
>>> data_nml = parser.read('data.nml')
"""
# For switching based on files versus paths
nml_is_path = not hasattr(nml_fnam... | python | {
"resource": ""
} |
q9331 | Parser._readstream | train | def _readstream(self, nml_file, nml_patch_in=None):
"""Parse an input stream containing a Fortran namelist."""
nml_patch = nml_patch_in if nml_patch_in is not None else Namelist()
tokenizer = Tokenizer()
f90lex = []
for line in nml_file:
toks = tokenizer.parse(line)
... | python | {
"resource": ""
} |
q9332 | Parser._parse_indices | train | def _parse_indices(self):
"""Parse a sequence of Fortran vector indices as a list of tuples."""
v_name = self.prior_token
v_indices = []
while self.token in (',', '('):
v_indices.append(self._parse_index(v_name))
return v_indices | python | {
"resource": ""
} |
q9333 | Parser._parse_index | train | def _parse_index(self, v_name):
"""Parse Fortran vector indices into a tuple of Python indices."""
i_start = i_end = i_stride = None
# Start index
self._update_tokens()
try:
i_start = int(self.token)
self._update_tokens()
except ValueError:
... | python | {
"resource": ""
} |
q9334 | Parser._parse_value | train | def _parse_value(self, write_token=True, override=None):
"""Convert string repr of Fortran type to equivalent Python type."""
v_str = self.prior_token
# Construct the complex string
if v_str == '(':
v_re = self.token
self._update_tokens(write_token)
... | python | {
"resource": ""
} |
q9335 | Parser._update_tokens | train | def _update_tokens(self, write_token=True, override=None,
patch_skip=False):
"""Update tokens to the next available values."""
next_token = next(self.tokens)
patch_value = ''
patch_tokens = ''
if self.pfile and write_token:
token = override if... | python | {
"resource": ""
} |
q9336 | Parser._append_value | train | def _append_value(self, v_values, next_value, v_idx=None, n_vals=1):
"""Update a list of parsed values with a new value."""
for _ in range(n_vals):
if v_idx:
try:
v_i = next(v_idx)
except StopIteration:
# Repeating comma... | python | {
"resource": ""
} |
q9337 | display_pil_image | train | def display_pil_image(im):
"""Displayhook function for PIL Images, rendered as PNG."""
from IPython.core import display
b = BytesIO()
im.save(b, format='png')
data = b.getvalue()
ip_img = display.Image(data=data, format='png', embed=True)
return ip_img._repr_png_() | python | {
"resource": ""
} |
q9338 | AppNexusClient._prepare_uri | train | def _prepare_uri(self, service_name, **parameters):
"""Prepare the URI for a request
:param service_name: The target service
:type service_name: str
:param kwargs: query parameters
:return: The uri of the request
"""
query_parameters = []
for key, value i... | python | {
"resource": ""
} |
q9339 | AppNexusClient._handle_rate_exceeded | train | def _handle_rate_exceeded(self, response): # pragma: no cover
"""Handles rate exceeded errors"""
waiting_time = int(response.headers.get("Retry-After", 10))
time.sleep(waiting_time) | python | {
"resource": ""
} |
q9340 | AppNexusClient.update_token | train | def update_token(self):
"""Request a new token and store it for future use"""
logger.info('updating token')
if None in self.credentials.values():
raise RuntimeError("You must provide an username and a password")
credentials = dict(auth=self.credentials)
url = self.tes... | python | {
"resource": ""
} |
q9341 | AppNexusClient.check_errors | train | def check_errors(self, response, data):
"""Check for errors and raise an appropriate error if needed"""
if "error_id" in data:
error_id = data["error_id"]
if error_id in self.error_ids:
raise self.error_ids[error_id](response)
if "error_code" in data:
... | python | {
"resource": ""
} |
q9342 | AppNexusClient.get | train | def get(self, service_name, **kwargs):
"""Retrieve data from AppNexus API"""
return self._send(requests.get, service_name, **kwargs) | python | {
"resource": ""
} |
q9343 | AppNexusClient.modify | train | def modify(self, service_name, json, **kwargs):
"""Modify an AppNexus object"""
return self._send(requests.put, service_name, json, **kwargs) | python | {
"resource": ""
} |
q9344 | AppNexusClient.create | train | def create(self, service_name, json, **kwargs):
"""Create a new AppNexus object"""
return self._send(requests.post, service_name, json, **kwargs) | python | {
"resource": ""
} |
q9345 | AppNexusClient.delete | train | def delete(self, service_name, *ids, **kwargs):
"""Delete an AppNexus object"""
return self._send(requests.delete, service_name, id=ids, **kwargs) | python | {
"resource": ""
} |
q9346 | GraphWin.plot | train | def plot(self, x, y, color="black"):
"""
Uses coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self) | python | {
"resource": ""
} |
q9347 | GraphWin.plotPixel | train | def plotPixel(self, x, y, color="black"):
"""
Doesn't use coordinant system.
"""
p = Point(x, y)
p.fill(color)
p.draw(self)
p.t = lambda v: v
p.tx = lambda v: v
p.ty = lambda v: v | python | {
"resource": ""
} |
q9348 | GraphWin.getMouse | train | def getMouse(self):
"""
Waits for a mouse click.
"""
# FIXME: this isn't working during an executing cell
self.mouse_x.value = -1
self.mouse_y.value = -1
while self.mouse_x.value == -1 and self.mouse_y.value == -1:
time.sleep(.1)
return (self.m... | python | {
"resource": ""
} |
q9349 | event_html_page_context | train | def event_html_page_context(app, pagename, templatename, context, doctree):
"""Called when the HTML builder has created a context dictionary to render a template with.
Conditionally adding disqus.js to <head /> if the directive is used in a page.
:param sphinx.application.Sphinx app: Sphinx application ob... | python | {
"resource": ""
} |
q9350 | DisqusDirective.get_shortname | train | def get_shortname(self):
"""Validate and returns disqus_shortname config value.
:returns: disqus_shortname config value.
:rtype: str
"""
disqus_shortname = self.state.document.settings.env.config.disqus_shortname
if not disqus_shortname:
raise ExtensionError(... | python | {
"resource": ""
} |
q9351 | DisqusDirective.get_identifier | train | def get_identifier(self):
"""Validate and returns disqus_identifier option value.
:returns: disqus_identifier config value.
:rtype: str
"""
if 'disqus_identifier' in self.options:
return self.options['disqus_identifier']
title_nodes = self.state.document.tra... | python | {
"resource": ""
} |
q9352 | DisqusDirective.run | train | def run(self):
"""Executed by Sphinx.
:returns: Single DisqusNode instance with config values passed as arguments.
:rtype: list
"""
disqus_shortname = self.get_shortname()
disqus_identifier = self.get_identifier()
return [DisqusNode(disqus_shortname, disqus_ident... | python | {
"resource": ""
} |
q9353 | attach | train | def attach(func, params):
"""
Given a function and a namespace of possible parameters,
bind any params matching the signature of the function
to that function.
"""
sig = inspect.signature(func)
params = Projection(sig.parameters.keys(), params)
return functools.partial(func, **params) | python | {
"resource": ""
} |
q9354 | init_config | train | def init_config(overrides):
"""
Install the config dict as pmxbot.config, setting overrides,
and return the result.
"""
pmxbot.config = config = ConfigDict()
config.setdefault('bot_nickname', 'pmxbot')
config.update(overrides)
return config | python | {
"resource": ""
} |
q9355 | initialize | train | def initialize(config):
"Initialize the bot with a dictionary of config items"
config = init_config(config)
_setup_logging()
_load_library_extensions()
if not Handler._registry:
raise RuntimeError("No handlers registered")
class_ = _load_bot_class()
config.setdefault('log_channels', [])
config.setdefault('... | python | {
"resource": ""
} |
q9356 | Sentinel.augment_items | train | def augment_items(cls, items, **defaults):
"""
Iterate over the items, keeping a adding properties as supplied by
Sentinel objects encountered.
>>> from more_itertools.recipes import consume
>>> res = Sentinel.augment_items(['a', 'b', NoLog, 'c'], secret=False)
>>> res = tuple(res)
>>> consume(map(print,... | python | {
"resource": ""
} |
q9357 | Handler.find_matching | train | def find_matching(cls, message, channel):
"""
Yield ``cls`` subclasses that match message and channel
"""
return (
handler
for handler in cls._registry
if isinstance(handler, cls)
and handler.match(message, channel)
) | python | {
"resource": ""
} |
q9358 | Handler._set_implied_name | train | def _set_implied_name(self):
"Allow the name of this handler to default to the function name."
if getattr(self, 'name', None) is None:
self.name = self.func.__name__
self.name = self.name.lower() | python | {
"resource": ""
} |
q9359 | CommandHandler._set_doc | train | def _set_doc(self, func):
"""
If no doc was explicitly set, use the function's docstring, trimming
whitespace and replacing newlines with spaces.
"""
if not self.doc and func.__doc__:
self.doc = func.__doc__.strip().replace('\n', ' ') | python | {
"resource": ""
} |
q9360 | Bot.allow | train | def allow(self, channel, message):
"""
Allow plugins to filter content.
"""
return all(
filter(channel, message)
for filter in _load_filters()
) | python | {
"resource": ""
} |
q9361 | Bot._handle_output | train | def _handle_output(self, channel, output):
"""
Given an initial channel and a sequence of messages or sentinels,
output the messages.
"""
augmented = Sentinel.augment_items(output, channel=channel, secret=False)
for message in augmented:
self.out(message.channel, message, not message.secret) | python | {
"resource": ""
} |
q9362 | Bot.handle_action | train | def handle_action(self, channel, nick, msg):
"Core message parser and dispatcher"
messages = ()
for handler in Handler.find_matching(msg, channel):
exception_handler = functools.partial(
self._handle_exception,
handler=handler,
)
rest = handler.process(msg)
client = connection = event = None
... | python | {
"resource": ""
} |
q9363 | Bot.handle_scheduled | train | def handle_scheduled(self, target):
"""
target is a Handler or simple callable
"""
if not isinstance(target, Handler):
return target()
return self._handle_scheduled(target) | python | {
"resource": ""
} |
q9364 | log_leave | train | def log_leave(event, nick, channel):
"""
Log a quit or part event.
"""
if channel not in pmxbot.config.log_channels:
return
ParticipantLogger.store.log(nick, channel, event.type) | python | {
"resource": ""
} |
q9365 | Karma.link | train | def link(self, thing1, thing2):
"""
Link thing1 and thing2, adding the karma of each into
a single entry.
If any thing does not exist, it is created.
"""
thing1 = thing1.strip().lower()
thing2 = thing2.strip().lower()
if thing1 == thing2:
raise SameName("Attempted to link two of the same name")
sel... | python | {
"resource": ""
} |
q9366 | SQLiteKarma._get | train | def _get(self, id):
"Return keys and value for karma id"
VALUE_SQL = "SELECT karmavalue from karma_values where karmaid = ?"
KEYS_SQL = "SELECT karmakey from karma_keys where karmaid = ?"
value = self.db.execute(VALUE_SQL, [id]).fetchall()[0][0]
keys_cur = self.db.execute(KEYS_SQL, [id]).fetchall()
keys = s... | python | {
"resource": ""
} |
q9367 | MongoDBKarma.repair_duplicate_names | train | def repair_duplicate_names(self):
"""
Prior to 1101.1.1, pmxbot would incorrectly create new karma records
for individuals with multiple names.
This routine corrects those records.
"""
for name in self._all_names():
cur = self.db.find({'names': name})
main_doc = next(cur)
for duplicate in cur:
... | python | {
"resource": ""
} |
q9368 | google | train | def google(rest):
"Look up a phrase on google"
API_URL = 'https://www.googleapis.com/customsearch/v1?'
try:
key = pmxbot.config['Google API key']
except KeyError:
return "Configure 'Google API key' in config"
# Use a custom search that searches everything normally
# http://stackoverflow.com/a/11206266/70170
... | python | {
"resource": ""
} |
q9369 | annoy | train | def annoy():
"Annoy everyone with meaningless banter"
def a1():
yield 'OOOOOOOHHH, WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield 'WHAT DO YOU DO WITH A DRUNKEN SAILOR'
yield "WHAT DO YOU DO WITH A DRUNKEN SAILOR, EARLY IN THE MORNIN'?"
def a2():
yield "I'M HENRY THE EIGHTH I AM"
yield "HENRY THE EIGHTH I AM... | python | {
"resource": ""
} |
q9370 | cheer | train | def cheer(rest):
"Cheer for something"
if rest:
karma.Karma.store.change(rest, 1)
return "/me cheers for %s!" % rest
karma.Karma.store.change('the day', 1)
return "/me cheers!" | python | {
"resource": ""
} |
q9371 | golfclap | train | def golfclap(rest):
"Clap for something"
clapv = random.choice(phrases.clapvl)
adv = random.choice(phrases.advl)
adj = random.choice(phrases.adjl)
if rest:
clapee = rest.strip()
karma.Karma.store.change(clapee, 1)
return "/me claps %s for %s, %s %s." % (clapv, rest, adv, adj)
return "/me claps %s, %s %s." %... | python | {
"resource": ""
} |
q9372 | oregontrail | train | def oregontrail(channel, nick, rest):
"It's edutainment!"
rest = rest.strip()
if rest:
who = rest.strip()
else:
who = random.choice([nick, channel, 'pmxbot'])
action = random.choice(phrases.otrail_actions)
if action in ('has', 'has died from'):
issue = random.choice(phrases.otrail_issues)
text = '%s %s %s... | python | {
"resource": ""
} |
q9373 | eball | train | def eball(rest):
"Ask the magic 8ball a question"
try:
url = 'https://8ball.delegator.com/magic/JSON/'
url += rest
result = requests.get(url).json()['magic']['answer']
except Exception:
result = util.wchoice(phrases.ball8_opts)
return result | python | {
"resource": ""
} |
q9374 | roll | train | def roll(rest, nick):
"Roll a die, default = 100."
if rest:
rest = rest.strip()
die = int(rest)
else:
die = 100
myroll = random.randint(1, die)
return "%s rolls %s" % (nick, myroll) | python | {
"resource": ""
} |
q9375 | ticker | train | def ticker(rest):
"Look up a ticker symbol's current trading value"
ticker = rest.upper()
# let's use Yahoo's nifty csv facility, and pull last time/price both
symbol = 's'
last_trade_price = 'l1'
last_trade_time = 't1'
change_percent = 'p2'
format = ''.join((symbol, last_trade_time, last_trade_price, change_pe... | python | {
"resource": ""
} |
q9376 | pick | train | def pick(rest):
"Pick between a few options"
question = rest.strip()
choices = util.splitem(question)
if len(choices) == 1:
return "I can't pick if you give me only one choice!"
else:
pick = random.choice(choices)
certainty = random.sample(phrases.certainty_opts, 1)[0]
return "%s... %s %s" % (pick, certain... | python | {
"resource": ""
} |
q9377 | lunch | train | def lunch(rest):
"Pick where to go to lunch"
rs = rest.strip()
if not rs:
return "Give me an area and I'll pick a place: (%s)" % (
', '.join(list(pmxbot.config.lunch_choices)))
if rs not in pmxbot.config.lunch_choices:
return "I didn't recognize that area; here's what i have: (%s)" % (
', '.join(list(pmxb... | python | {
"resource": ""
} |
q9378 | insult | train | def insult(rest):
"Generate a random insult from datahamster"
# not supplying any style will automatically redirect to a random
url = 'http://autoinsult.datahamster.com/'
ins_type = random.randrange(4)
ins_url = url + "?style={ins_type}".format(**locals())
insre = re.compile('<div class="insult" id="insult">(.*?)... | python | {
"resource": ""
} |
q9379 | bitchingisuseless | train | def bitchingisuseless(channel, rest):
"It really is, ya know..."
rest = rest.strip()
if rest:
karma.Karma.store.change(rest, -1)
else:
karma.Karma.store.change(channel, -1)
rest = "foo'"
advice = 'Quiet bitching is useless, %s. Do something about it.' % rest
return advice | python | {
"resource": ""
} |
q9380 | curse | train | def curse(rest):
"Curse the day!"
if rest:
cursee = rest
else:
cursee = 'the day'
karma.Karma.store.change(cursee, -1)
return "/me curses %s!" % cursee | python | {
"resource": ""
} |
q9381 | bless | train | def bless(rest):
"Bless the day!"
if rest:
blesse = rest
else:
blesse = 'the day'
karma.Karma.store.change(blesse, 1)
return "/me blesses %s!" % blesse | python | {
"resource": ""
} |
q9382 | blame | train | def blame(channel, rest, nick):
"Pass the buck!"
if rest:
blamee = rest
else:
blamee = channel
karma.Karma.store.change(nick, -1)
if random.randint(1, 10) == 1:
yield "/me jumps atop the chair and points back at %s." % nick
yield (
"stop blaming the world for your problems, you bitter, "
"two-faced s... | python | {
"resource": ""
} |
q9383 | calc | train | def calc(rest):
"Perform a basic calculation"
mo = calc_exp.match(rest)
if mo:
try:
return str(eval(rest))
except Exception:
return "eval failed... check your syntax"
else:
return "misformatted arithmetic!" | python | {
"resource": ""
} |
q9384 | define | train | def define(rest):
"Define a word"
word = rest.strip()
res = util.lookup(word)
fmt = (
'{lookup.provider} says: {res}' if res else
"{lookup.provider} does not have a definition for that.")
return fmt.format(**dict(locals(), lookup=util.lookup)) | python | {
"resource": ""
} |
q9385 | urbandict | train | def urbandict(rest):
"Define a word with Urban Dictionary"
word = rest.strip()
definition = util.urban_lookup(word)
if not definition:
return "Arg! I didn't find a definition for that."
return 'Urban Dictionary says {word}: {definition}'.format(**locals()) | python | {
"resource": ""
} |
q9386 | acit | train | def acit(rest):
"Look up an acronym"
word = rest.strip()
res = util.lookup_acronym(word)
if res is None:
return "Arg! I couldn't expand that..."
else:
return ' | '.join(res) | python | {
"resource": ""
} |
q9387 | version | train | def version(rest):
"Get the version of pmxbot or one of its plugins"
pkg = rest.strip() or 'pmxbot'
if pkg.lower() == 'python':
return sys.version.split()[0]
return importlib_metadata.version(pkg) | python | {
"resource": ""
} |
q9388 | timezone | train | def timezone(rest):
"""Convert date between timezones.
Example:
> !tz 11:00am UTC in PDT
11:00 UTC -> 4:00 PDT
UTC is implicit
> !tz 11:00am in PDT
11:00 UTC -> 4:00 PDT
> !tz 11:00am PDT
11:00 PDT -> 18:00 UTC
"""
if ' in ' in rest:
dstr, tzname = rest.split(' in ', 1)
else:
dstr, tzname = rest, ... | python | {
"resource": ""
} |
q9389 | SelectableStorage.finalize | train | def finalize(cls):
"Delete the various persistence objects"
for finalizer in cls._finalizers:
try:
finalizer()
except Exception:
log.exception("Error in finalizer %s", finalizer) | python | {
"resource": ""
} |
q9390 | pmon | train | def pmon(month):
"""
P the month
>>> print(pmon('2012-08'))
August, 2012
"""
year, month = month.split('-')
return '{month_name}, {year}'.format(
month_name=calendar.month_name[int(month)],
year=year,
) | python | {
"resource": ""
} |
q9391 | pday | train | def pday(dayfmt):
"""
P the day
>>> print(pday('2012-08-24'))
Friday the 24th
"""
year, month, day = map(int, dayfmt.split('-'))
return '{day} the {number}'.format(
day=calendar.day_name[calendar.weekday(year, month, day)],
number=inflect.engine().ordinal(day),
) | python | {
"resource": ""
} |
q9392 | patch_compat | train | def patch_compat(config):
"""
Support older config values.
"""
if 'web_host' in config:
config['host'] = config.pop('web_host')
if 'web_port' in config:
config['port'] = config.pop('web_port') | python | {
"resource": ""
} |
q9393 | ChannelPage.date_key | train | def date_key(cls, month_string):
"""
Return a key suitable for sorting by month.
>>> k1 = ChannelPage.date_key('September, 2012')
>>> k2 = ChannelPage.date_key('August, 2013')
>>> k2 > k1
True
"""
month, year = month_string.split(',')
month_ord = cls.month_ordinal[month]
return year, month_ord | python | {
"resource": ""
} |
q9394 | LegacyPage.forward | train | def forward(self, channel, date_s, fragment):
"""
Given an HREF in the legacy timezone, redirect to an href for UTC.
"""
time_s, sep, nick = fragment.rpartition('.')
time = datetime.datetime.strptime(time_s, '%H.%M.%S')
date = datetime.datetime.strptime(date_s, '%Y-%m-%d')
dt = datetime.datetime.combine(d... | python | {
"resource": ""
} |
q9395 | logs | train | def logs(channel):
"Where can one find the logs?"
default_url = 'http://' + socket.getfqdn()
base = pmxbot.config.get('logs URL', default_url)
logged_channel = channel in pmxbot.config.log_channels
path = '/channel/' + channel.lstrip('#') if logged_channel else '/'
return urllib.parse.urljoin(base, path) | python | {
"resource": ""
} |
q9396 | log | train | def log(channel, rest):
"""
Enable or disable logging for a channel;
use 'please' to start logging and 'stop please' to stop.
"""
words = [s.lower() for s in rest.split()]
if 'please' not in words:
return
include = 'stop' not in rest
existing = set(pmxbot.config.log_channels)
# add the channel if include, ot... | python | {
"resource": ""
} |
q9397 | MongoDBLogger._add_recent | train | def _add_recent(self, doc, logged_id):
"Keep a tab on the most recent message for each channel"
spec = dict(channel=doc['channel'])
doc['ref'] = logged_id
doc.pop('_id')
self._recent.replace_one(spec, doc, upsert=True) | python | {
"resource": ""
} |
q9398 | FullTextMongoDBLogger._has_fulltext | train | def _has_fulltext(cls, uri):
"""
Enable full text search on the messages if possible and return True.
If the full text search cannot be enabled, then return False.
"""
coll = cls._get_collection(uri)
with ExceptionTrap(storage.pymongo.errors.OperationFailure) as trap:
coll.create_index([('message', 'text... | python | {
"resource": ""
} |
q9399 | Bot._find_user_channel | train | def _find_user_channel(self, username):
"""
Use slacker to resolve the username to an opened IM channel
"""
user_id = self.slacker.users.get_user_id(username)
im = user_id and self.slacker.im.open(user_id).body['channel']['id']
return im and self.slack.server.channels.find(im) | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.