Re: [Tutor] Scheduling Python Execution
On 15/04/13 19:23, Zaki Akhmad wrote: On Mon, Apr 15, 2013 at 3:51 PM, Alan Gauld wrote: multiple cron jobs will be less work for your computer than running a long term program constantly checking times and launching your scripts... That's called reinventing the wheel with a square one... There are more modern (and more efficent) replacements for cron but given your requirements cron still looks like the best bet. Actually, I want to write a twitter bot which runs on a specific time. That is exactly what cron is designed to do. Although given that the time you want will vary, my guess is that the lesser-known "at" job will be better. Another option is the sched module, that lets you schedule tasks to run while your program is idling. It is not a replacement for cron or at, since it requires your program to be running. But for simple needs, it may do the job. http://docs.python.org/2/library/sched.html http://pymotw.com/2/sched/ For an idea, I'd like to have this twitter bot tweet every sunrise and sunset, everyday. Since everyday the sunrise and the sunset time are vary, what are the best way to do it? Sunrise and sunset *where*? Because the world is a globe, sunrise and sunset vary from place to place. Even in one place, they also vary at different times of the year. If you google for "sunrise sunset algorithm", you may find a formula for calculating the time of each at a given latitude and longitude. Or not. I don't really know how complicated it is. Should I entered the sunset and the sunrise manually? I don't know about "manually", but there's no standard Python command for giving you sunset and sunrise. You'll either need to find an existing program that does it, or write one yourself. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scheduling Python Execution
I assume that you are getting these times from somewhere, hopefully a website. To do as Steve says, you would just scrape (or use the API if there is one) to get the times, and schedule a tweet at that time. If you do use cron you can make use of https://pypi.python.org/pypi/python-crontab On 15 April 2013 10:23, Zaki Akhmad wrote: > On Mon, Apr 15, 2013 at 3:51 PM, Alan Gauld > wrote: > > > multiple cron jobs will be less work for your computer than running a > long > > term program constantly checking times and launching your scripts... > That's > > called reinventing the wheel with a square one... > > > > There are more modern (and more efficent) replacements for cron but given > > your requirements cron still looks like the best bet. > > Actually, > > I want to write a twitter bot which runs on a specific time. For an > idea, I'd like to have this twitter bot tweet every sunrise and > sunset, everyday. Since everyday the sunrise and the sunset time are > vary, what are the best way to do it? > > Should I entered the sunset and the sunrise manually? > > Thanks! > -- > Zaki Akhmad > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > -- ./Sven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scheduling Python Execution
> I want to write a twitter bot which runs on a specific time. For an > idea, I'd like to have this twitter bot tweet every sunrise and > sunset, everyday. Since everyday the sunrise and the sunset time are > vary, what are the best way to do it? Have the bot calculate sunrise and sunset for the following day and re-schedule itself for those times. This email and any attachment to it are confidential. Unless you are the intended recipient, you may not use, copy or disclose either the message or any information contained in the message. If you are not the intended recipient, you should delete this email and notify the sender immediately. Any views or opinions expressed in this email are those of the sender only, unless otherwise stated. All copyright in any Capita material in this email is reserved. All emails, incoming and outgoing, may be recorded by Capita and monitored for legitimate business purposes. Capita exclude all liability for any loss or damage arising or resulting from the receipt, use or transmission of this email to the fullest extent permitted by law. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scheduling Python Execution
On Mon, Apr 15, 2013 at 3:51 PM, Alan Gauld wrote: > multiple cron jobs will be less work for your computer than running a long > term program constantly checking times and launching your scripts... That's > called reinventing the wheel with a square one... > > There are more modern (and more efficent) replacements for cron but given > your requirements cron still looks like the best bet. Actually, I want to write a twitter bot which runs on a specific time. For an idea, I'd like to have this twitter bot tweet every sunrise and sunset, everyday. Since everyday the sunrise and the sunset time are vary, what are the best way to do it? Should I entered the sunset and the sunrise manually? Thanks! -- Zaki Akhmad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Scheduling Python Execution
On 15/04/13 06:59, Zaki Akhmad wrote: I'd like to execute python script for specific times. I prefer not to use cron, since this times will be very varies. multiple cron jobs will be less work for your computer than running a long term program constantly checking times and launching your scripts... That's called reinventing the wheel with a square one... There are more modern (and more efficent) replacements for cron but given your requirements cron still looks like the best bet. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor