I have good experience with PHP and Python frameworks for scripting, so now I'm taking a step towards Pyramid.
I would like to know what the “correct” way to run a script in Pyramid is. That is, how should I configure it so that it is part of the application and has access to config and, therefore, to the database, but does not start through pasteur (or any other WSGI).
As an example, let's say I have a web application that, when the user is offline, captures Facebook updates through the web service. I want to write a script to poll this service and store it in a database ready for next login.
How do I do this in terms of:
- Adding variables to ini file
- Running the script correctly
I understand the basics of Python modules and packages; however, I do not quite understand the Configurator / Paster / package configuration, in which I suspect the answer lies.
thank
Update:
Thanks, this looks like what I'm looking for. I note that you need to follow a specific structure (for example, have pivot and parser attributes) and that a function called command () will always be run. My test code now looks something like this:
class AwesomeCommand(Command):
max_args = 2
min_args = 2
usage = "NAME"
summary = "Say hello!"
group_name = "My Package Name"
parser = Command.standard_parser(verbose=True)
def command(self):
config_file, section_name = self.args
Now I'm stuck on how to get the settings myself. For example, in init.py you can do this:
engine = engine_from_config(settings, 'sqlalchemy.')
What do I need to do to convert the configuration file to settings?
EDIT: (simpler) way to do it in Pylons:
Run Pylons controller as a standalone application?