repost: http web page fetch question

Discussion in 'Python' started by grocery_stocker, Apr 24, 2009.

  1. Given the following...

    [cdalten@localhost oakland]$ more basic.py
    #!/usr/bin/python

    import sched
    import time

    scheduler = sched.scheduler(time.time, time.sleep)

    def print_event(name):
    print 'EVENT:', time.time(), name

    print 'START:', time.time()
    scheduler.enter(2, 1, print_event, ('first',))

    scheduler.run()
    [cdalten@localhost oakland]$ ./basic.py
    START: 1240584506.06
    EVENT: 1240584508.06 first
    [cdalten@localhost oakland]$


    How do I modify it so that it runs every hour on the hour.
     
    grocery_stocker, Apr 24, 2009
    #1
    1. Advertising

  2. grocery_stocker wrote:
    > Given the following...
    >
    > [cdalten@localhost oakland]$ more basic.py

    <snip>
    >
    > How do I modify it so that it runs every hour on the hour.


    I'd probably use cron, but here's one way.

    Emile
    -----

    import sched
    import time

    scheduler = sched.scheduler(time.time, time.sleep)

    def print_event(count,rescheduler):
    print 'EVENT:', time.time(), count
    rescheduler.enter(2,1,print_event,(count+1,rescheduler))

    print 'START:', time.time()
    scheduler.enter(2, 1, print_event, (1,scheduler))

    scheduler.run()
     
    Emile van Sebille, Apr 24, 2009
    #2
    1. Advertising

  3. grocery_stocker wrote:
    > Given the following...
    >
    > [cdalten@localhost oakland]$ more basic.py

    <snip>
    >
    > How do I modify it so that it runs every hour on the hour.


    I'd probably use cron, but here's one way.

    Emile
    -----

    import sched
    import time

    scheduler = sched.scheduler(time.time, time.sleep)

    def print_event(count,rescheduler):
    print 'EVENT:', time.time(), count
    rescheduler.enter(2,1,print_event,(count+1,rescheduler))

    print 'START:', time.time()
    scheduler.enter(2, 1, print_event, (1,scheduler))

    scheduler.run()
     
    Emile van Sebille, Apr 24, 2009
    #3
  4. En Fri, 24 Apr 2009 11:54:40 -0300, grocery_stocker <>
    escribió:

    > scheduler = sched.scheduler(time.time, time.sleep)
    >
    > How do I modify it so that it runs every hour on the hour.


    (The sched module is almost useless, IMHO)

    I'd use cron (linux) or schtasks (windows).
    If it has to be a Python script, I'd just use time.sleep:

    def compute_delay_until_next_hour():
    now = time.localtime()
    secs_past_hour = now.tm_min * 60 + now.tm_sec
    delay = 60*60 - secs_past_hour
    return delay

    # do_something() # optional
    while True:
    dt = compute_delay_until_next_hour()
    time.sleep(dt)
    do_something()

    --
    Gabriel Genellina
     
    Gabriel Genellina, Apr 25, 2009
    #4
  5. En Fri, 24 Apr 2009 11:54:40 -0300, grocery_stocker <>
    escribió:

    > scheduler = sched.scheduler(time.time, time.sleep)
    >
    > How do I modify it so that it runs every hour on the hour.


    (The sched module is almost useless, IMHO)

    I'd use cron (linux) or schtasks (windows).
    If it has to be a Python script, I'd just use time.sleep:

    def compute_delay_until_next_hour():
    now = time.localtime()
    secs_past_hour = now.tm_min * 60 + now.tm_sec
    delay = 60*60 - secs_past_hour
    return delay

    # do_something() # optional
    while True:
    dt = compute_delay_until_next_hour()
    time.sleep(dt)
    do_something()

    --
    Gabriel Genellina
     
    Gabriel Genellina, Apr 25, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Hirst

    RePost - HTTP Transfer

    Jason Hirst, Aug 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    337
    vMike
    Aug 24, 2003
  2. Martin
    Replies:
    2
    Views:
    289
    Anthony Jones
    Feb 14, 2008
  3. grocery_stocker

    http web fetch question

    grocery_stocker, Apr 23, 2009, in forum: Python
    Replies:
    3
    Views:
    245
    grocery_stocker
    Apr 24, 2009
  4. आलोक (Alok)

    A java class to fetch the contents of a web page

    आलोक (Alok), Jun 18, 2009, in forum: Java
    Replies:
    3
    Views:
    1,005
    Arne Vajhøj
    Jun 24, 2009
  5. Barry
    Replies:
    9
    Views:
    1,395
    Kushal Kumaran
    May 27, 2010
Loading...

Share This Page