XBMC Trailer Downloader - scrapes HD-Trailers.net and downloads trailers from movietrailers.apple.com Would love some feedback - its my first real Python project

I am coming with a list of suggestions to make it more Pythonic/prettier.

  • Look at how to setup comments, docstrings etc(https://www.python.org/dev/peps/pep-0008/) and general very good reference to read a few times.
  • Imports should be organized by Standard libraries, Third party, And utilities with one line between.

    import os import time

    from bs4 import BeautifulSoup from configobj import ConfigObj import requests

  • Import from is better if you only use a few things, because you can see what the depedencies are, and change them later on.

  • Instead of the ini file, use a python file with a dictionary object instead. This will save you like 50-100 lines of code.

  • Read about python logging, it can remove lot of the writedebug etc. To a simple start just use log = logging.getLogger() logging.basicConfig() log.setLevel(logging.DEBUG)

    now you can do

    log.debug("hi") log.info("HI")

    ... etc

  • Combine strings with format instead. This saves you lot of unexpected exceptions. print("ham" + somevar)

    replaced with

    print("ham {}".format(somevar))

  • This is very subjective, but I like to give more detailed names of functions. E.g. checkDirectory does not only checkdirectory, but also makes it. I would call it mkdirGraceful("") or something like that.

  • Global variables are evil. So consider moving some state code out of the supposely clean functions. E.g. downloadLink function updates the state, but maybe it should just be a "download link" function, and the function that calls it should update the state. This makes it more testable and easier to work/change.

  • You mix tabs and spaces as indentation. Only use spaces! I personally hate spaces, but 99.9% of Python code use space, so I just do the same.

It is lot of things I mentioned, and I only took the most basic, but we have all been there. Just keep writing code and find out how to simplify it.

One thing that might help you develop faster is pychecker. It is static type checker for python - it doesn't work perfect since Python is not strongly typed, but it helps nonetheless.

/r/coolgithubprojects Thread Link - github.com