#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Over there -->
    Posts
    49
    Rep Power
    11

    'Simple' wget script problem!


    Hi folks

    PHP Code:


    #!/usr/bin/python

    import timeos

    while 1:

        
    t=time.localtime()
        
    n=120*t[3]+2*t[4]+int(t[5]/30)
        
    filename='FYP_CAM' 'n'


    command='wget --output-document=/home/users/damalo/public_html/'+filename+' http://128.214.69.103/jpg/image.jpg'

    os.system(command)

    # wait 10 s and get next image

    time.sleep(10
    When i run this script (python grab.py) from in linux i just get..well nothing! Any ideas? Im new to the python scene so i think it may be something small.

    Cheers,
    damalo
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    "while 1:" means loop forever.

    These:
    Code:
        t=time.localtime()
        n=120*t[3]+2*t[4]+int(t[5]/30)
        filename='FYP_CAM' + 'n'
    are being looped forever. Nothing else is called.
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Besides the infinte loop pointed out by sbf, the first thing that jumps out is that your concatenating the letter 'n' to the end of the filename variable, not the value of n. Change this line to:

    filename = 'FYP_CAM' + str(n)

    Also, unless you decide to import division from __future__ somewhere in your program then you don't need to convert the value returned by the division at the end of n to an int() since it will be done implicitly; as shown here:

    Code:
    Last login: Fri Jan 14 12:40:58 on console
    Welcome to Darwin!
    Mark-Smiths-Computer:~ Mark$ python
    Python 2.3 (#1, Sep 13 2003, 00:49:11) 
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import time
    >>> t = time.localtime()
    >>>
    >>> n = 120 * t[3] + 2 * t[4] + int(t[5] / 30)
    >>> n
    1582
    >>> n = 120 * t[3] + 2 * t[4] + t[5] / 30 
    >>> n
    1582
    >>>
    >>> from __future__ import division
    >>> n = 120 * t[3] + 2 * t[4] + t[5] / 30
    >>> n
    1582.6666666666667
    >>> 
    >>> n = int(120 * t[3] + 2 * t[4] + t[5] / 30)
    >>> n
    1582
    >>>
    Take care ,

    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Over there -->
    Posts
    49
    Rep Power
    11
    That seems to have sorted it alright - my sleep thing isnt working now but ill probably be able to fix that. Thanks for pointing it out
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Your problem is that only the filename calculation is done inside the while loop, if you indent the rest of your program then everything should work fine .
    Last edited by netytan; January 14th, 2005 at 10:12 AM. Reason: Typo
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    Over there -->
    Posts
    49
    Rep Power
    11
    Oh! just indent it!?..............and it works

    Thanks a mill!

IMN logo majestic logo threadwatch logo seochat tools logo