I'm not very good at putting into words what I'm thinking, so I do 
apologize for not being very clear.

I was hoping there might be a way to do "one-off" type scripts using the 
DAL and Auth features to test code that can print to a console. You are 
right, for this particular use case an MVC framework isn't needed since 
it's not web related at all. 

Yesterday the only way I knew how to do such a thing was by running the 
py.exe executable with an argument for the file you wanted to run, but that 
doesn't seem to work on non-windows platforms. After looking into it a bit 
more today, the --run=PYTHON_FILE argument available from command line 
might be what I need.

Thanks for the tip the other day, by the way, it was a pretty simple 
question and setting migrate=False worked perfectly.

On Wednesday, 7 May 2014 18:01:38 UTC-4, Niphlod wrote:
>
> ok. now you just have to explain what do you mean by "running in web2py 
> environment". 
> If you don't want to use models or controllers (and surely do not want 
> views), why do you need an MVC (Model-View-Controller) framework 
> environment to work in? 
>
> On Wednesday, May 7, 2014 10:38:52 PM UTC+2, Spencer Underwood wrote:
>>
>>
>> Greetings,
>>
>> This might be a really dumb or simple question or might better suited to 
>> ask in the IRC channel, but I can't seem to find an answer to this anywhere 
>> on google. I've been trying to test various bits of code to see how it runs 
>> on the web2py framework but without tying it to a specific view. Does 
>> anyone know how to run a script / function in a module based off of events 
>> such as a button press or a input command to the web shell?
>>
>> I made a simple function in a module which, provided a valid API Key, 
>> Verification Code and Character ID, parses and stores a list of mail 
>> messages pulled from the 
>> MailMessage<http://wiki.eve-id.net/APIv2_Char_MailMessages_XML>function made 
>> available by the EVE Online API Server. There is also a 
>> function which will do the same as before but for every valid API Key, 
>> Verification Code and Character ID stored in the database all at once. I'm 
>> working on a means to properly handle the other API calls 
>> available<http://wiki.eve-id.net/APIv2_Page_Index>and would like to run 
>> those on a semi-regular basis, but haven't currently 
>> achieved a working result yet. I intended to invoke these method when a 
>> user logs into the site, as well as roughly once every twelve hours, to 
>> keep a relatively up-to-date database filled with mails for EVE Online. 
>>
>> All relevant ID columns for things like Character ID, Message ID, etc... 
>> from the API server are unique so a quick IS_NOT_IN_DB and a unique key 
>> constraint should stop any and all duplicates. I guess later I could log 
>> attempts to enter a duplicate value, but right now it's not a concern. 
>>
>> From my understanding, any code in the Model or Controller folders will 
>> be executed each time the page is viewed. This works well for a lot of 
>> things, but doesn't seem optimal for relatively slow net and database code. 
>> The Scheduler seems like it could be useful for this, but that doesn't seem 
>> like it should be placed in a model or a controller file.
>>
>> Here is what I've used so far to read messages and pull them to a 
>> database, it's pretty crude but I just wanted a working example to build 
>> off of later.
>>
>> the EVE API class is a python library (found 
>> here<https://github.com/ntt/eveapi>) 
>> which does the job of parsing the XML data returned from the API server 
>> into an iterable data structure. 
>>
>> # Put your userID and apiKey (full access) here before running this 
>> script.
>> YOUR_KEYID = [redacted]
>> YOUR_VCODE = "[redacted]"
>> YOUR_CHARACTERID=[redacted]
>>
>> from os.path import join, exists
>> from httplib import HTTPException
>> from gluon.sql import DAL, Field
>> from gluon.validators import *
>>
>> import logging
>>
>> import eveapi
>> import datetime
>>
>> api = eveapi.EVEAPIConnection()
>> db = DAL('sqlite://test3.sqlite')
>>
>> #----------------------------------------------------------------------------
>> message = db.define_table('message', 
>> Field('messageID','integer', unique=True),
>> Field('header','string'),Field('body','string'), 
>> Field('dateTimeSent','datetime'))
>>
>> #    /account/Characters.xml.aspx
>> getMailHeader = api("/char/MailMessages", keyID=YOUR_KEYID, 
>> vCode=YOUR_VCODE, characterID=YOUR_CHARACTERID)
>>
>> listOfMessageID = []
>> listOfHeaders = []
>>
>> result = getMailHeader.messages.SortedBy("sentDate")
>> for s in result:
>> try:
>> db.message.insert(messageID=s.get("messageID"), header=s.get("title"), 
>> dateTimeSent = datetime.datetime.utcfromtimestamp( s.get("sentDate") ) , 
>> body="")
>> listOfMessageID.append(s.get("messageID"))
>> except Exception as e:
>> logging.warning("Message with ID of %s already exists in database", 
>> s.get("messageID"))
>>
>> if len(listOfMessageID) > 0:
>> getMailBody = api("/char/MailBodies", keyID=YOUR_KEYID, vCode=YOUR_VCODE, 
>> characterID=YOUR_CHARACTERID, ids = ','.join([ str(i) for i in 
>> listOfMessageID]) )
>> MailMessages = getMailBody.messages.SortedBy("messageID")
>>
>> for s in MailMessages:
>> mailID = s.get("messageID")
>> mailBody = s.get("data").encode("utf-8")
>> db( db[message].messageID==mailID).update(**{"body":mailBody})
>> #print s.__str__().encode("utf-8")
>> #print
>>
>> for row in db(message).select():
>> print row
>> print
>> db.commit()
>>
>> Thanks,
>> Spencer Underwood
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to