signature
stringlengths
8
3.44k
body
stringlengths
0
1.41M
docstring
stringlengths
1
122k
id
stringlengths
5
17
@property<EOL><INDENT>def location_name(self):<DEDENT>
return self._location_name<EOL>
The name of the station.
f9605:c3:m3
@property<EOL><INDENT>def train_services(self):<DEDENT>
return self._train_services<EOL>
A list of train services that appear on this board. Empty if there are none
f9605:c3:m4
@property<EOL><INDENT>def bus_services(self):<DEDENT>
return self._bus_services<EOL>
A list of bus services that appear on this board. Empty if there are none
f9605:c3:m5
@property<EOL><INDENT>def ferry_services(self):<DEDENT>
return self._ferry_services<EOL>
A list of ferry services that appear on this board. Empty if there are none
f9605:c3:m6
@property<EOL><INDENT>def nrcc_messages(self):<DEDENT>
return self._nrcc_messages<EOL>
An optional list of important messages that should be displayed with the station board. Messages may include HTML hyperlinks and paragraphs
f9605:c3:m7
@property<EOL><INDENT>def sta(self):<DEDENT>
return self._sta<EOL>
Scheduled Time of Arrival. This is optional and may be present for station boards which include arrivals. This is a human readable string rather than a proper datetime object and may not be a time at all
f9605:c4:m4
@property<EOL><INDENT>def eta(self):<DEDENT>
return self._eta<EOL>
Estimated Time of Arrival. This is optional and may be present when an sta (Scheduled Time of Arrival) is available. This is a human readable string rather than a proper datetime object and may not be a time at all
f9605:c4:m5
@property<EOL><INDENT>def std(self):<DEDENT>
return self._std<EOL>
Scheduled Time of Departure. This is optional and may be present for station boards which include departures This is a human readable string rather than a proper datetime object and may not be a time at all
f9605:c4:m6
@property<EOL><INDENT>def etd(self):<DEDENT>
return self._etd<EOL>
Estimated Time of Departure. This is optional and may be present for results which contain an std (Scheduled Time of Departure) This is a human readable string rather than a proper datetime object and may not be a time at all
f9605:c4:m7
@property<EOL><INDENT>def platform(self):<DEDENT>
return self._platform<EOL>
The platform number for the service at this station. Optional.
f9605:c4:m8
@property<EOL><INDENT>def operator_name(self):<DEDENT>
return self._operator_name<EOL>
The name of the train operator
f9605:c4:m9
@property<EOL><INDENT>def operator_code(self):<DEDENT>
return self._operator_code<EOL>
The National Rail abbreviation for the train operator
f9605:c4:m10
@property<EOL><INDENT>def is_circular_route(self):<DEDENT>
return self._is_circular_route<EOL>
If True this service is following a circular route and will call again at this station.
f9605:c5:m1
@property<EOL><INDENT>def service_id(self):<DEDENT>
return self._service_id<EOL>
The unique ID of this service. This ID is specific to the Darwin LDB Service
f9605:c5:m2
@property<EOL><INDENT>def origins(self):<DEDENT>
return self._origins<EOL>
A list of ServiceLocation objects describing the origins of this service. A service may have more than multiple origins.
f9605:c5:m3
@property<EOL><INDENT>def destinations(self):<DEDENT>
return self._destinations<EOL>
A list of ServiceLocation objects describing the destinations of this service. A service may have more than multiple destinations.
f9605:c5:m4
@property<EOL><INDENT>def destination_text(self):<DEDENT>
return self._location_formatter(self.destinations)<EOL>
Human readable string describing the destination(s) of this service
f9605:c5:m5
@property<EOL><INDENT>def origin_text(self):<DEDENT>
return self._location_formatter(self.origins)<EOL>
Human readable string describing the origin(s) of this service
f9605:c5:m6
@property<EOL><INDENT>def location_name(self):<DEDENT>
return self._location_name<EOL>
Location name
f9605:c6:m0
@property<EOL><INDENT>def crs(self):<DEDENT>
return self._crs<EOL>
The CRS code of the location
f9605:c6:m1
@property<EOL><INDENT>def via(self):<DEDENT>
return self._via<EOL>
An optional string that should be displayed alongside the location_name. This provides additional context regarding an ambiguous route.
f9605:c6:m2
@property<EOL><INDENT>def future_change_to(self):<DEDENT>
return self._future_change_to<EOL>
An optional string that indicates a service type (Bus/Ferry/Train) which will replace the current service type in the future.
f9605:c6:m3
@property<EOL><INDENT>def is_cancelled(self):<DEDENT>
return self._is_cancelled<EOL>
True if this service is cancelled at this location.
f9605:c7:m2
@property<EOL><INDENT>def disruption_reason(self):<DEDENT>
return self._disruption_reason<EOL>
A string containing a disruption reason for this service, if it is delayed or cancelled.
f9605:c7:m3
@property<EOL><INDENT>def overdue_message(self):<DEDENT>
return self._overdue_message<EOL>
A string that describes an overdue event
f9605:c7:m4
@property<EOL><INDENT>def ata(self):<DEDENT>
return self._ata<EOL>
Actual Time of Arrival. A human readable string, not guaranteed to be a machine-parsable time
f9605:c7:m5
@property<EOL><INDENT>def atd(self):<DEDENT>
return self._atd<EOL>
Actual Time of Departure. A human readable string, not guaranteed to be a machine-parsable time
f9605:c7:m6
@property<EOL><INDENT>def location_name(self):<DEDENT>
return self._location_name<EOL>
Location Name The name of the location from which the details of this service are being accessed and to which the service attributes such as times correspond.
f9605:c7:m7
@property<EOL><INDENT>def crs(self):<DEDENT>
return self._crs<EOL>
The CRS code corresponding to the location_name property.
f9605:c7:m8
@property<EOL><INDENT>def previous_calling_point_lists(self):<DEDENT>
return self._previous_calling_point_lists<EOL>
A list of CallingPointLists. The first CallingPointList is all the calling points of the through train from its origin up until immediately before here, with any additional CallingPointLIsts (if they are present) containing the calling points of associated trains which join the through train from their respective origins through to the calling point at which they join with the through train.
f9605:c7:m9
@property<EOL><INDENT>def subsequent_calling_point_lists(self):<DEDENT>
return self._subsequent_calling_point_lists<EOL>
A list of CallingPointLists. The first CallingPointList is all the calling points of the through train after here until its destination, with any additional CallingPointLists (if they are present) containing the calling points of associated trains which split from the through train from the calling point at which they split off from the through train until their respective destinations.
f9605:c7:m10
@property<EOL><INDENT>def previous_calling_points(self):<DEDENT>
calling_points = list()<EOL>for cpl in self._previous_calling_point_lists:<EOL><INDENT>calling_points += cpl.calling_points<EOL><DEDENT>return calling_points<EOL>
A list of CallingPoint objects. This is the list of all previous calling points for the service, including all associated services if multiple services join together to form this service.
f9605:c7:m11
@property<EOL><INDENT>def subsequent_calling_points(self):<DEDENT>
calling_points = list()<EOL>for cpl in self._subsequent_calling_point_lists:<EOL><INDENT>calling_points += cpl.calling_points<EOL><DEDENT>return calling_points<EOL>
A list of CallingPoint objects. This is the list of all subsequent calling points for the service, including all associated services if the service splits into multiple services.
f9605:c7:m12
@property<EOL><INDENT>def location_name(self):<DEDENT>
return self._location_name<EOL>
Location name
f9605:c8:m0
@property<EOL><INDENT>def crs(self):<DEDENT>
return self._crs<EOL>
The CRS code for this location
f9605:c8:m1
@property<EOL><INDENT>def at(self):<DEDENT>
return self._at<EOL>
Actual time Human readable string, no guaranteed format
f9605:c8:m2
@property<EOL><INDENT>def et(self):<DEDENT>
return self._et<EOL>
Estimated time Human readable string, no guaranteed format
f9605:c8:m3
@property<EOL><INDENT>def st(self):<DEDENT>
return self._st<EOL>
Scheduled time Human readable string, no guaranteed format
f9605:c8:m4
@property<EOL><INDENT>def calling_points(self):<DEDENT>
return self._calling_points<EOL>
List of CallingPoint objects All the calling points contained within this calling point list
f9605:c9:m2
@property<EOL><INDENT>def service_type(self):<DEDENT>
return self._service_type<EOL>
Service type The service type of the service with these calling points (e.g. "train")
f9605:c9:m3
@property<EOL><INDENT>def service_change_required(self):<DEDENT>
return self._service_change_required<EOL>
Service change required A boolean indicating whether a change is required between the through service and the service to these calling points.
f9605:c9:m4
@property<EOL><INDENT>def association_is_cancelled(self):<DEDENT>
return self._association_is_cancelled<EOL>
Association is cancelled A boolean indicating whether this association is cancelled.
f9605:c9:m5
@property<EOL><INDENT>def host_name(self):<DEDENT>
return self._host_name<EOL>
Get the host name.
f9618:c0:m1
@property<EOL><INDENT>def running(self):<DEDENT>
return self._scheduler.running<EOL>
Get true whether the scheduler is running.
f9618:c0:m2
@property<EOL><INDENT>def state(self):<DEDENT>
return self._scheduler.state<EOL>
Get the state of the scheduler.
f9618:c0:m3
@property<EOL><INDENT>def scheduler(self):<DEDENT>
return self._scheduler<EOL>
Get the base scheduler.
f9618:c0:m4
@property<EOL><INDENT>def task(self):<DEDENT>
return self._scheduler.scheduled_job<EOL>
Get the base scheduler decorator
f9618:c0:m5
def init_app(self, app):
self.app = app<EOL>self.app.apscheduler = self<EOL>self._load_config()<EOL>self._load_jobs()<EOL>if self.api_enabled:<EOL><INDENT>self._load_api()<EOL><DEDENT>
Initialize the APScheduler with a Flask application instance.
f9618:c0:m6
def start(self, paused=False):
if self.host_name not in self.allowed_hosts and '<STR_LIT:*>' not in self.allowed_hosts:<EOL><INDENT>LOGGER.debug('<STR_LIT>' %<EOL>(self.host_name, '<STR_LIT:U+002C>'.join(self.allowed_hosts)))<EOL>return<EOL><DEDENT>self._scheduler.start(paused=paused)<EOL>
Start the scheduler. :param bool paused: if True, don't start job processing until resume is called.
f9618:c0:m7
def shutdown(self, wait=True):
self._scheduler.shutdown(wait)<EOL>
Shut down the scheduler. Does not interrupt any currently running jobs. :param bool wait: ``True`` to wait until all currently executing jobs have finished :raises SchedulerNotRunningError: if the scheduler has not been started yet
f9618:c0:m8
def pause(self):
self._scheduler.pause()<EOL>
Pause job processing in the scheduler. This will prevent the scheduler from waking up to do job processing until :meth:`resume` is called. It will not however stop any already running job processing.
f9618:c0:m9
def resume(self):
self._scheduler.resume()<EOL>
Resume job processing in the scheduler.
f9618:c0:m10
def add_listener(self, callback, mask=EVENT_ALL):
self._scheduler.add_listener(callback, mask)<EOL>
Add a listener for scheduler events. When a matching event occurs, ``callback`` is executed with the event object as its sole argument. If the ``mask`` parameter is not provided, the callback will receive events of all types. For further info: https://apscheduler.readthedocs.io/en/latest/userguide.html#scheduler-events :param callback: any callable that takes one argument :param int mask: bitmask that indicates which events should be listened to
f9618:c0:m11
def remove_listener(self, callback):
self._scheduler.remove_listener(callback)<EOL>
Remove a previously added event listener.
f9618:c0:m12
def add_job(self, id, func, **kwargs):
job_def = dict(kwargs)<EOL>job_def['<STR_LIT:id>'] = id<EOL>job_def['<STR_LIT>'] = func<EOL>job_def['<STR_LIT:name>'] = job_def.get('<STR_LIT:name>') or id<EOL>fix_job_def(job_def)<EOL>return self._scheduler.add_job(**job_def)<EOL>
Add the given job to the job list and wakes up the scheduler if it's already running. :param str id: explicit identifier for the job (for modifying it later) :param func: callable (or a textual reference to one) to run at the given time
f9618:c0:m13
def delete_job(self, id, jobstore=None):
warnings.warn('<STR_LIT>', DeprecationWarning)<EOL>self.remove_job(id, jobstore)<EOL>
DEPRECATED, use remove_job instead. Remove a job, preventing it from being run any more. :param str id: the identifier of the job :param str jobstore: alias of the job store that contains the job
f9618:c0:m14
def delete_all_jobs(self, jobstore=None):
warnings.warn('<STR_LIT>', DeprecationWarning)<EOL>self.remove_all_jobs(jobstore)<EOL>
DEPRECATED, use remove_all_jobs instead. Remove all jobs from the specified job store, or all job stores if none is given. :param str|unicode jobstore: alias of the job store
f9618:c0:m15
def remove_job(self, id, jobstore=None):
self._scheduler.remove_job(id, jobstore)<EOL>
Remove a job, preventing it from being run any more. :param str id: the identifier of the job :param str jobstore: alias of the job store that contains the job
f9618:c0:m16
def remove_all_jobs(self, jobstore=None):
self._scheduler.remove_all_jobs(jobstore)<EOL>
Remove all jobs from the specified job store, or all job stores if none is given. :param str|unicode jobstore: alias of the job store
f9618:c0:m17
def get_job(self, id, jobstore=None):
return self._scheduler.get_job(id, jobstore)<EOL>
Return the Job that matches the given ``id``. :param str id: the identifier of the job :param str jobstore: alias of the job store that most likely contains the job :return: the Job by the given ID, or ``None`` if it wasn't found :rtype: Job
f9618:c0:m18
def get_jobs(self, jobstore=None):
return self._scheduler.get_jobs(jobstore)<EOL>
Return a list of pending jobs (if the scheduler hasn't been started yet) and scheduled jobs, either from a specific job store or from all of them. :param str jobstore: alias of the job store :rtype: list[Job]
f9618:c0:m19
def modify_job(self, id, jobstore=None, **changes):
fix_job_def(changes)<EOL>if '<STR_LIT>' in changes:<EOL><INDENT>trigger, trigger_args = pop_trigger(changes)<EOL>self._scheduler.reschedule_job(id, jobstore, trigger, **trigger_args)<EOL><DEDENT>return self._scheduler.modify_job(id, jobstore, **changes)<EOL>
Modify the properties of a single job. Modifications are passed to this method as extra keyword arguments. :param str id: the identifier of the job :param str jobstore: alias of the job store that contains the job
f9618:c0:m20
def pause_job(self, id, jobstore=None):
self._scheduler.pause_job(id, jobstore)<EOL>
Pause the given job until it is explicitly resumed. :param str id: the identifier of the job :param str jobstore: alias of the job store that contains the job
f9618:c0:m21
def resume_job(self, id, jobstore=None):
self._scheduler.resume_job(id, jobstore)<EOL>
Resume the schedule of the given job, or removes the job if its schedule is finished. :param str id: the identifier of the job :param str jobstore: alias of the job store that contains the job
f9618:c0:m22
def run_job(self, id, jobstore=None):
job = self._scheduler.get_job(id, jobstore)<EOL>if not job:<EOL><INDENT>raise JobLookupError(id)<EOL><DEDENT>job.func(*job.args, **job.kwargs)<EOL>
Run the given job without scheduling it. :param id: the identifier of the job. :param str jobstore: alias of the job store that contains the job :return:
f9618:c0:m23
def authenticate(self, func):
self._authentication_callback = func<EOL>return func<EOL>
A decorator that is used to register a function to authenticate a user. :param func: The callback to authenticate.
f9618:c0:m24
def _load_config(self):
options = dict()<EOL>job_stores = self.app.config.get('<STR_LIT>')<EOL>if job_stores:<EOL><INDENT>options['<STR_LIT>'] = job_stores<EOL><DEDENT>executors = self.app.config.get('<STR_LIT>')<EOL>if executors:<EOL><INDENT>options['<STR_LIT>'] = executors<EOL><DEDENT>job_defaults = self.app.config.get('<STR_LIT>')<EOL>if job_defaults:<EOL><INDENT>options['<STR_LIT>'] = job_defaults<EOL><DEDENT>timezone = self.app.config.get('<STR_LIT>')<EOL>if timezone:<EOL><INDENT>options['<STR_LIT>'] = timezone<EOL><DEDENT>self._scheduler.configure(**options)<EOL>self.auth = self.app.config.get('<STR_LIT>', self.auth)<EOL>self.api_enabled = self.app.config.get('<STR_LIT>', self.api_enabled) <EOL>self.api_enabled = self.app.config.get('<STR_LIT>', self.api_enabled)<EOL>self.api_prefix = self.app.config.get('<STR_LIT>', self.api_prefix)<EOL>self.endpoint_prefix = self.app.config.get('<STR_LIT>', self.endpoint_prefix)<EOL>self.allowed_hosts = self.app.config.get('<STR_LIT>', self.allowed_hosts)<EOL>
Load the configuration from the Flask configuration.
f9618:c0:m25
def _load_jobs(self):
jobs = self.app.config.get('<STR_LIT>')<EOL>if not jobs:<EOL><INDENT>jobs = self.app.config.get('<STR_LIT>')<EOL><DEDENT>if jobs:<EOL><INDENT>for job in jobs:<EOL><INDENT>self.add_job(**job)<EOL><DEDENT><DEDENT>
Load the job definitions from the Flask configuration.
f9618:c0:m26
def _load_api(self):
self._add_url_route('<STR_LIT>', '<STR_LIT>', api.get_scheduler_info, '<STR_LIT:GET>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.add_job, '<STR_LIT:POST>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.get_job, '<STR_LIT:GET>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.get_jobs, '<STR_LIT:GET>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.delete_job, '<STR_LIT>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.update_job, '<STR_LIT>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.pause_job, '<STR_LIT:POST>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.resume_job, '<STR_LIT:POST>')<EOL>self._add_url_route('<STR_LIT>', '<STR_LIT>', api.run_job, '<STR_LIT:POST>')<EOL>
Add the routes for the scheduler API.
f9618:c0:m27
def _add_url_route(self, endpoint, rule, view_func, method):
if self.api_prefix:<EOL><INDENT>rule = self.api_prefix + rule<EOL><DEDENT>if self.endpoint_prefix:<EOL><INDENT>endpoint = self.endpoint_prefix + endpoint<EOL><DEDENT>self.app.add_url_rule(<EOL>rule,<EOL>endpoint,<EOL>self._apply_auth(view_func),<EOL>methods=[method]<EOL>)<EOL>
Add a Flask route. :param str endpoint: The endpoint name. :param str rule: The endpoint url. :param view_func: The endpoint func :param str method: The http method.
f9618:c0:m28
def _apply_auth(self, view_func):
@functools.wraps(view_func)<EOL>def decorated(*args, **kwargs):<EOL><INDENT>if not self.auth:<EOL><INDENT>return view_func(*args, **kwargs)<EOL><DEDENT>auth_data = self.auth.get_authorization()<EOL>if auth_data is None:<EOL><INDENT>return self._handle_authentication_error()<EOL><DEDENT>if not self._authentication_callback or not self._authentication_callback(auth_data):<EOL><INDENT>return self._handle_authentication_error()<EOL><DEDENT>return view_func(*args, **kwargs)<EOL><DEDENT>return decorated<EOL>
Apply decorator to authenticate the user who is making the request. :param view_func: The flask view func.
f9618:c0:m29
def _handle_authentication_error(self):
response = make_response('<STR_LIT>')<EOL>response.headers['<STR_LIT>'] = self.auth.get_authenticate_header()<EOL>response.status_code = <NUM_LIT><EOL>return response<EOL>
Return an authentication error.
f9618:c0:m30
def get_authorization_header():
header = request.environ.get('<STR_LIT>')<EOL>if not header:<EOL><INDENT>return None<EOL><DEDENT>header = wsgi_to_bytes(header)<EOL>try:<EOL><INDENT>auth_type, auth_info = header.split(None, <NUM_LIT:1>)<EOL>auth_type = auth_type.lower()<EOL><DEDENT>except ValueError:<EOL><INDENT>return None<EOL><DEDENT>return auth_type, auth_info<EOL>
Return request's 'Authorization:' header as a two-tuple of (type, info).
f9619:m0
def get_authorization(self):
raise NotImplemented()<EOL>
Get the authorization header. :return Authentication: The authentication data or None if it is not present or invalid.
f9619:c1:m0
def get_authenticate_header(self):
pass<EOL>
Return the value of `WWW-Authenticate` header in a `401 Unauthenticated` response.
f9619:c1:m1
def get_authorization(self):
auth = get_authorization_header()<EOL>if not auth:<EOL><INDENT>return None<EOL><DEDENT>auth_type, auth_info = auth<EOL>if auth_type != b'<STR_LIT>':<EOL><INDENT>return None<EOL><DEDENT>try:<EOL><INDENT>username, password = base64.b64decode(auth_info).split(b'<STR_LIT::>', <NUM_LIT:1>)<EOL><DEDENT>except Exception:<EOL><INDENT>return None<EOL><DEDENT>return Authorization('<STR_LIT>', username=bytes_to_wsgi(username), password=bytes_to_wsgi(password))<EOL>
Get the username and password for Basic authentication header. :return Authentication: The authentication data or None if it is not present or invalid.
f9619:c2:m0
def get_authenticate_header(self):
return '<STR_LIT>' % self.www_authenticate_realm<EOL>
Return the value of `WWW-Authenticate` header in a `401 Unauthenticated` response.
f9619:c2:m1
def job_to_dict(job):
data = OrderedDict()<EOL>data['<STR_LIT:id>'] = job.id<EOL>data['<STR_LIT:name>'] = job.name<EOL>data['<STR_LIT>'] = job.func_ref<EOL>data['<STR_LIT:args>'] = job.args<EOL>data['<STR_LIT>'] = job.kwargs<EOL>data.update(trigger_to_dict(job.trigger))<EOL>if not job.pending:<EOL><INDENT>data['<STR_LIT>'] = job.misfire_grace_time<EOL>data['<STR_LIT>'] = job.max_instances<EOL>data['<STR_LIT>'] = None if job.next_run_time is None else job.next_run_time<EOL><DEDENT>return data<EOL>
Converts a job to an OrderedDict.
f9622:m0
def pop_trigger(data):
trigger_name = data.pop('<STR_LIT>')<EOL>trigger_args = {}<EOL>if trigger_name == '<STR_LIT:date>':<EOL><INDENT>trigger_arg_names = ('<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>elif trigger_name == '<STR_LIT>':<EOL><INDENT>trigger_arg_names = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>elif trigger_name == '<STR_LIT>':<EOL><INDENT>trigger_arg_names = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>' % trigger_name)<EOL><DEDENT>for arg_name in trigger_arg_names:<EOL><INDENT>if arg_name in data:<EOL><INDENT>trigger_args[arg_name] = data.pop(arg_name)<EOL><DEDENT><DEDENT>return trigger_name, trigger_args<EOL>
Pops trigger and trigger args from a given dict.
f9622:m1
def trigger_to_dict(trigger):
data = OrderedDict()<EOL>if isinstance(trigger, DateTrigger):<EOL><INDENT>data['<STR_LIT>'] = '<STR_LIT:date>'<EOL>data['<STR_LIT>'] = trigger.run_date<EOL><DEDENT>elif isinstance(trigger, IntervalTrigger):<EOL><INDENT>data['<STR_LIT>'] = '<STR_LIT>'<EOL>data['<STR_LIT>'] = trigger.start_date<EOL>if trigger.end_date:<EOL><INDENT>data['<STR_LIT>'] = trigger.end_date<EOL><DEDENT>w, d, hh, mm, ss = extract_timedelta(trigger.interval)<EOL>if w > <NUM_LIT:0>:<EOL><INDENT>data['<STR_LIT>'] = w<EOL><DEDENT>if d > <NUM_LIT:0>:<EOL><INDENT>data['<STR_LIT>'] = d<EOL><DEDENT>if hh > <NUM_LIT:0>:<EOL><INDENT>data['<STR_LIT>'] = hh<EOL><DEDENT>if mm > <NUM_LIT:0>:<EOL><INDENT>data['<STR_LIT>'] = mm<EOL><DEDENT>if ss > <NUM_LIT:0>:<EOL><INDENT>data['<STR_LIT>'] = ss<EOL><DEDENT><DEDENT>elif isinstance(trigger, CronTrigger):<EOL><INDENT>data['<STR_LIT>'] = '<STR_LIT>'<EOL>if trigger.start_date:<EOL><INDENT>data['<STR_LIT>'] = trigger.start_date<EOL><DEDENT>if trigger.end_date:<EOL><INDENT>data['<STR_LIT>'] = trigger.end_date<EOL><DEDENT>for field in trigger.fields:<EOL><INDENT>if not field.is_default:<EOL><INDENT>data[field.name] = str(field)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>data['<STR_LIT>'] = str(trigger)<EOL><DEDENT>return data<EOL>
Converts a trigger to an OrderedDict.
f9622:m2
def fix_job_def(job_def):
if six.PY2 and isinstance(job_def.get('<STR_LIT>'), six.text_type):<EOL><INDENT>job_def['<STR_LIT>'] = str(job_def.get('<STR_LIT>'))<EOL><DEDENT>if isinstance(job_def.get('<STR_LIT>'), six.string_types):<EOL><INDENT>job_def['<STR_LIT>'] = dateutil.parser.parse(job_def.get('<STR_LIT>'))<EOL><DEDENT>if isinstance(job_def.get('<STR_LIT>'), six.string_types):<EOL><INDENT>job_def['<STR_LIT>'] = dateutil.parser.parse(job_def.get('<STR_LIT>'))<EOL><DEDENT>if isinstance(job_def.get('<STR_LIT>'), six.string_types):<EOL><INDENT>job_def['<STR_LIT>'] = dateutil.parser.parse(job_def.get('<STR_LIT>'))<EOL><DEDENT>if isinstance(job_def.get('<STR_LIT>'), dict):<EOL><INDENT>trigger = job_def.pop('<STR_LIT>')<EOL>job_def['<STR_LIT>'] = trigger.pop('<STR_LIT:type>', '<STR_LIT:date>')<EOL>job_def.update(trigger)<EOL><DEDENT>
Replaces the datetime in string by datetime object.
f9622:m3
def get_scheduler_info():
scheduler = current_app.apscheduler<EOL>d = OrderedDict([<EOL>('<STR_LIT>', scheduler.host_name),<EOL>('<STR_LIT>', scheduler.allowed_hosts),<EOL>('<STR_LIT>', scheduler.running)<EOL>])<EOL>return jsonify(d)<EOL>
Gets the scheduler info.
f9623:m0
def add_job():
data = request.get_json(force=True)<EOL>try:<EOL><INDENT>job = current_app.apscheduler.add_job(**data)<EOL>return jsonify(job)<EOL><DEDENT>except ConflictingIdError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % data.get('<STR_LIT:id>')), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Adds a new job.
f9623:m1
def delete_job(job_id):
try:<EOL><INDENT>current_app.apscheduler.remove_job(job_id)<EOL>return Response(status=<NUM_LIT>)<EOL><DEDENT>except JobLookupError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Deletes a job.
f9623:m2
def get_job(job_id):
job = current_app.apscheduler.get_job(job_id)<EOL>if not job:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>return jsonify(job)<EOL>
Gets a job.
f9623:m3
def get_jobs():
jobs = current_app.apscheduler.get_jobs()<EOL>job_states = []<EOL>for job in jobs:<EOL><INDENT>job_states.append(job)<EOL><DEDENT>return jsonify(job_states)<EOL>
Gets all scheduled jobs.
f9623:m4
def update_job(job_id):
data = request.get_json(force=True)<EOL>try:<EOL><INDENT>current_app.apscheduler.modify_job(job_id, **data)<EOL>job = current_app.apscheduler.get_job(job_id)<EOL>return jsonify(job)<EOL><DEDENT>except JobLookupError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Updates a job.
f9623:m5
def pause_job(job_id):
try:<EOL><INDENT>current_app.apscheduler.pause_job(job_id)<EOL>job = current_app.apscheduler.get_job(job_id)<EOL>return jsonify(job)<EOL><DEDENT>except JobLookupError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Pauses a job.
f9623:m6
def resume_job(job_id):
try:<EOL><INDENT>current_app.apscheduler.resume_job(job_id)<EOL>job = current_app.apscheduler.get_job(job_id)<EOL>return jsonify(job)<EOL><DEDENT>except JobLookupError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Resumes a job.
f9623:m7
def run_job(job_id):
try:<EOL><INDENT>current_app.apscheduler.run_job(job_id)<EOL>job = current_app.apscheduler.get_job(job_id)<EOL>return jsonify(job)<EOL><DEDENT>except JobLookupError:<EOL><INDENT>return jsonify(dict(error_message='<STR_LIT>' % job_id), status=<NUM_LIT>)<EOL><DEDENT>except Exception as e:<EOL><INDENT>return jsonify(dict(error_message=str(e)), status=<NUM_LIT>)<EOL><DEDENT>
Executes a job.
f9623:m8
def get_docker_secret(name, default=None, cast_to=str, autocast_name=True, getenv=True, safe=True,<EOL>secrets_dir=os.path.join(root, '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):
<EOL>name_secret = name.lower() if autocast_name else name<EOL>name_env = name.upper() if autocast_name else name<EOL>value = None<EOL>try:<EOL><INDENT>with open(os.path.join(secrets_dir, name_secret), '<STR_LIT:r>') as secret_file:<EOL><INDENT>value = secret_file.read()<EOL><DEDENT><DEDENT>except IOError as e:<EOL><INDENT>if getenv:<EOL><INDENT>value = os.environ.get(name_env)<EOL><DEDENT><DEDENT>if value is None:<EOL><INDENT>value = default<EOL><DEDENT>try:<EOL><INDENT>if value is None:<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if cast_to == bool:<EOL><INDENT>if value not in ('<STR_LIT:True>', '<STR_LIT:true>', '<STR_LIT:False>', '<STR_LIT:false>'):<EOL><INDENT>raise ValueError('<STR_LIT>' % value)<EOL><DEDENT>value = <NUM_LIT:1> if value in ('<STR_LIT:True>', '<STR_LIT:true>') else <NUM_LIT:0><EOL><DEDENT>return cast_to(value)<EOL><DEDENT>except (TypeError, ValueError) as e:<EOL><INDENT>if safe:<EOL><INDENT>return default<EOL><DEDENT>raise e<EOL><DEDENT>
This function fetches a docker secret :param name: the name of the docker secret :param default: the default value if no secret found :param cast_to: casts the value to the given type :param autocast_name: whether the name should be lowercase for secrets and upper case for environment :param getenv: if environment variable should be fetched as fallback :param safe: Whether the function should raise exceptions :param secrets_dir: the directory where the secrets are stored :returns: docker secret or environment variable depending on params :raises TypeError: if cast fails due to wrong type (None) :raises ValueError: if casts fails due to Value
f9625:m0
def setup_dogpile_logging(request):
logging.debug('<STR_LIT>')<EOL>return {'<STR_LIT>': [], <EOL>}<EOL>
calls_raw = ordered list of calls
f9628:m1
def _derive_db(self):
client = self<EOL>while hasattr(client, '<STR_LIT>'):<EOL><INDENT>client = client.proxied<EOL><DEDENT>if hasattr(client, '<STR_LIT>'):<EOL><INDENT>client = client.client<EOL>self._connection_kwargs = client.connection_pool.connection_kwargs<EOL>self._db = self._connection_kwargs['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self._connection_kwargs = False<EOL>self._db = '<STR_LIT>'<EOL><DEDENT>
this may not have a client on __init__, so this is deferred to a @property descriptor
f9628:c0:m0
def busca_cep_correios(cep):
if cep is None or not isinstance(cep, str):<EOL><INDENT>raise AttributeError("<STR_LIT>")<EOL><DEDENT>elif not cep.isdigit() or len(cep) != <NUM_LIT:8>:<EOL><INDENT>raise AttributeError("<STR_LIT>")<EOL><DEDENT>url = '<STR_LIT>'<EOL>payload = {'<STR_LIT>': cep, '<STR_LIT>': '<STR_LIT>', '<STR_LIT>': '<STR_LIT:N>'}<EOL>resp = requests.post(url, data=payload)<EOL>if resp.status_code != <NUM_LIT:200>:<EOL><INDENT>raise Exception("<STR_LIT>", resp.status_code)<EOL><DEDENT>from bs4 import BeautifulSoup<EOL>soup = BeautifulSoup(resp.text, "<STR_LIT>")<EOL>value_cells = soup.find('<STR_LIT>', attrs={'<STR_LIT:class>': '<STR_LIT>'})<EOL>values = list(value_cells.findAll('<STR_LIT>'))<EOL>texto_clean = []<EOL>for value in values[<NUM_LIT:1>].findAll('<STR_LIT>'):<EOL><INDENT>texto_clean.append(value.get_text().strip())<EOL><DEDENT>logradouro = Logradouro(texto_clean)<EOL>return logradouro<EOL>
Pesquisa o CEP informado no site dos correios
f9631:m0
def main(api_key, token):
trello_client = TrelloClient(<EOL>api_key=api_key,<EOL>token=token,<EOL>)<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>for board in trello_client.list_boards():<EOL><INDENT>print('<STR_LIT>'.format(board=board))<EOL><DEDENT>
List out the boards for our client
f9635:m0
def main(api_key, token, board_id):
trello_client = TrelloClient(<EOL>api_key=api_key,<EOL>token=token,<EOL>)<EOL>board = Board(client=trello_client, board_id=board_id)<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>for card_list in board.all_lists():<EOL><INDENT>print('<STR_LIT>'.format(card_list=card_list))<EOL><DEDENT>
List out the board lists for our client
f9636:m0
def make_trello_card(*args, **kwargs):
<EOL>board = Board(client=trello_client, board_id=TRELLO_BOARD_ID)<EOL>card_list = List(board=board, list_id=TRELLO_LIST_ID)<EOL>return card_list.add_card(*args, **kwargs)<EOL>
Generate a new Trello card
f9638:m0
def send_slack_message(channel, text):
http = httplib2.Http()<EOL>return http.request(SLACK_MESSAGE_URL, '<STR_LIT:POST>', body=json.dumps({<EOL>'<STR_LIT>': channel,<EOL>'<STR_LIT:text>': text,<EOL>}))<EOL>
Send a message to Slack
f9638:m1
def setUp(self):
self.app = app.test_client()<EOL>
Start a server to test on
f9639:c0:m0
@app.route('<STR_LIT:/>')<EOL>def root():
return '<STR_LIT>'<EOL>
Reply to curious persons
f9640:m0