Page 1 of 2 12 LastLast
Results 1 to 10 of 138

Thread: [Beginner] Programming Challenge: 4

Hybrid View

  1. #1
    Join Date
    Apr 2007
    Beans
    14,781

    [Beginner] Programming Challenge: 4

    The last challenge was rather simple. All the languages used had all the functions built into the language.

    Here is the last challenge: http://ubuntuforums.org/showthread.php?t=884394

    For this one, I ask that non beginners (that means you slavik) do not post anything except possible advice. DO NOT POST SOLUTIONS IF YOU ARE NOT A BEGINNER!


    The Challenge:
    Now that we dealt with user IO and file IO, lets do a little networking. Most languages do not have this built in, but some have standard library functions for it.

    The challenge will be simple, but will require the use of either another library or exploring the standard libraries. As many of you are using Python it seems, I will tell you that Python has standard libraries to do everything here, so explore the documentation page (you'll find that programmers spend a lot of time reviewing API's and documentation, so might as well practice now)

    You will have to do the following:

    • Write a program that will read a webpage and puts its text into a file named "index.xhtml"
    • The test site will be: http://laroza.freehostia.com/home/index.php
    • That is the bare minimum requirements, but I would ask you try to make it work for any site.


    You do NOT have to:

    • Have it do anything but download the single file of a web page, so ignore any external scripts or css.
    • Have it to any rendering, just write it to a file (for opening with a browser, most likely)


    For extra credit:

    • Have either prompt or use a command line argument to do do this with any webpage
    • Have it name the output file after the title of the document (hint: text in the elements <title></title>, you can use xml or html parsers for this, or you can use regular expressions)


    The test page is valid XHTML 1.1 (and is valid XML). All conditions and extra credit can be done with standard Python. If you use another language or non standard libs, let me know exactly how to get your entry working.



    Rules:
    Do not copy code, but you can obviously read it

    Try not to comment on other submissions. It will be hard to judge changing entries. If you edit your code, post the new version and make it clear there is a new code.

    How it will be judged
    • It has to do what it is specified.


    As before, try to follow the following (although I think it won't come down to judging on this, as the challenge will be tricky for beginners):
    • Clean code. Readable code is a must for being a programmer who wishes to possibly interact with others. Some languages can be more readable than others, so it will be judged on the effort of writing clean code, not which language is easier to read by design.
    • Logical code. Be a programmer, not a code monkey
    • Commented code. If something is possibly unclear (like an obscure use of math), let the readers know. Do not over comment, and let the code speak for itself whenever you can. Have logical variable names and function names. (Excessive commenting is a minus factor)
    • Working code. It has to work as it is posted. The codw will be read on the forum, so remember to use this guide to paste code if you don't know how: http://ubuntuforums.org/showthread.php?t=606009
    Last edited by LaRoza; August 14th, 2008 at 06:01 PM.

  2. #2
    Join Date
    Jan 2006
    Beans
    Hidden!
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: [Beginner] Programming Challenge: 4



    I would've done it in C and Perl, too ...
    I am infallible, you should know that by now.
    "My favorite language is call STAR. It's extremely concise. It has exactly one verb '*', which does exactly what I want at the moment." --Larry Wall
    (02:15:31 PM) ***TimToady and snake oil go way back...
    42 lines of Perl - SHI - Home Site

  3. #3
    Join Date
    Nov 2006
    Location
    Pennsylvania
    Beans
    423

    Re: [Beginner] Programming Challenge: 4

    The website isn't a valid url. not sure if you meant for this or not.

    Did you mean this? http://laroza.freehostia.com/home/index.php
    Your Ubuntu User number is # 15355

    A must Read for anyone interested in Computer Programming.

  4. #4
    Join Date
    Mar 2008
    Beans
    1,755

    Re: [Beginner] Programming Challenge: 4

    Ehh, I was running through some example code on a tutorial and couldn't figure out why it was not working. Turns out that link you gave is dead.

  5. #5
    Join Date
    Dec 2006
    Location
    Birmingham, England
    Beans
    83
    Distro
    Ubuntu 6.06 Dapper

    Re: [Beginner] Programming Challenge: 4

    When you say:
    ...puts its text into a file named "index.xhtml"
    Do you mean the source text, or just the words we see in a browser? Like this:
    LaRoza
    Computer Programming

    1. Home
    2. How to Start
    3. Forums
    4. Contact
    5. Applications

    Learning to Program

    See the Language Selector for a test to see what languages you might be interested in learning.

    * Learn to Program - My Wiki
    * Programming in Ubuntu
    * Learn to Program Forum

    Valid XHTML 1.1
    Also, thanks for keeping this going.

    EDIT: Should page come out without any of the colours or have I done something wrong?
    Last edited by M_the_C; August 14th, 2008 at 06:02 PM.

  6. #6
    Join Date
    Apr 2007
    Location
    (X,Y,Z) = (0,0,0)
    Beans
    3,715

    Re: [Beginner] Programming Challenge: 4

    Do I qualify as a beginner?

  7. #7
    Join Date
    Sep 2007
    Beans
    Hidden!

    Re: [Beginner] Programming Challenge: 4

    You should know for yourself ^

  8. #8
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 4

    Quote Originally Posted by slavik View Post


    I would've done it in C and Perl, too ...
    Well, you can do a fancy one at the end, but for now, I'd like beginners to figure it out on their own. It isn't fair to them to post first (like you did last time. If your answer had been readable, I'd have moved it)

    Quote Originally Posted by Titan8990 View Post
    Ehh, I was running through some example code on a tutorial and couldn't figure out why it was not working. Turns out that link you gave is dead.
    Fixed it. Sorry about that.

    Quote Originally Posted by M_the_C View Post
    When you say:
    Do you mean the source text, or just the words we see in a browser? Like this:
    Also, thanks for keeping this going.
    The source of the file. You don't have to deal with markup (unless you do the title thing).

    Go to the site, and view the source.

  9. #9
    Join Date
    Mar 2008
    Beans
    1,755

    Re: [Beginner] Programming Challenge: 4

    Here is my first draft. I will come up with another that will include the "extra credit".

    PHP Code:
    #!/usr/bin/env python

    import urllib2

    xhtml_file 
    open("index.xhtml""w")

    web urllib2.urlopen('http://laroza.freehostia.com/home/index.php')

    xhtml_file.write(web.read())

    xhtml_file.close() 

    What is considered a "non-standard" library? Is it anything you have to import or libraries that are not included in the standard python package?

  10. #10
    Join Date
    Apr 2007
    Beans
    14,781

    Re: [Beginner] Programming Challenge: 4

    Quote Originally Posted by Titan8990 View Post
    What is considered a "non-standard" library? Is it anything you have to import or libraries that are not included in the standard python package?
    Not part of the standard language. That is a standard library for Python.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •