[Tutor] Designing a program (File-Fetcher)
Alan Gauld
alan.gauld at btinternet.com
Fri Mar 15 02:02:21 CET 2013
On 14/03/13 21:25, Christopher Emery wrote:
> Okay, I know the best way to learn how to do something is to jump in so
> I have decided I would like to make a program (command line) to get
> files from a website that will be then used later on by another program.
OK, thats a good place to start.
Next step, having thought about what you want, is to step back and pick
a single scenario and build that. Once it workls add the next thing you
want, repeat till complete.
> Program idea - quick steps to do
> ***
> file-fetcher (within zip file)
>
> get internet location of files (ex: http://www.get_file.get/file_??.zip
> get name of files
These can be interactively from a user or from a config file
or from command line arguments.
> check date of file
> download file
This could use the ftp module if the far end has an ftp server running.
> unzip file
Using the zipfile module?
> delete zip file after saving the txt file
Yep, that looks like a fair start.
> ***
>
> Here are the things I need it to do:
> * if its ran just with its name file-fetcher.py then it should ask for
> location of file(s)
using input() and a test of sys.argv
> * it should also ask for a list of files to download seperated by a
> corma "," or by a file with a line by line list of files to download
you need to work out how you identify which it is. For starters stick
with a single file input by the user...
> * it should be able to download files that are zip or other format such
> as txt,
ok, but pick one to start.
> * if its ran with file-fetcher.py -L=url -F=file.zip, file.txt
worry about options later and look at the various modules for parsing
command line options - there are a few variants.
> * if its a zip file it need to extract the file(s) from it
> * it then need to put the downloaded, extracted files into a directory
> * it then needs to delete the zip file
zipfile, the os and shutil modules should all help here.
> * it needs to check for the date before downloading the whole file,
> maybe download the first few bytes to check time stamp
if its ftp then the standard ftp commands should do all you need.
> Okay with the above said, how should I start to do psceduo code?
you almost have above.
> Would each of the above be a function within the program?
probably.
> Any advise on class that exist that can make this process easier?
see above for useful modules.
read the documentation for each.
experiment at the >>> prompt.
> How would someone run a command that is normally done at the command
> line like espeak within python program?
look at the subprocess module documentation.
> Also how would I hide the
> visual output of a command like espeak, it throws alot of erros but it
> works, it happens to others using it too.
see last comment.
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list