Forum New Posts Notifier for NiftyHost
04-29-2011, 12:33 AM, (This post was last modified: 04-29-2011, 03:37 PM by RichardGv.)
#15
RE: Forum New Posts Notifier for NiftyHost
Nightly, April 28th, the version that have taken me days of effort:
https://github.com/richardgv/newpostsche...tscheck.py
  • Sad news firstly: This version requires Python 3.2, since it utilized the argparse library introduced in the version. Users have to upgrade the Python interpreter. This is non-negotiable.
  • External configuration files are now supported, i.e. from now on you need not to modify the script itself to add your usernames and passwords or modify any settings (actually, most settings). Configurations are stored in XML format (in order to make it "eXtensible"), parsed with xml.parsers.expat, and can be generated by the script using ElementTree or lxml library. lxml is a widely-used faster and more powerful XML processing library, which is not included in Python package itself, and Windows users may install it with the installers that you can find in the link, while the Linux/BSD users... Well, you know it. When the script fails to load lxml, it would use the ElementTree library as fallback, which lacks the support of CDATA sections.
    Quote:How to generate a skeleton configuration file?
    For *nix users it's easy:
    Code:
    python3.2 newpostscheck.py -o niftyhost -g newpostscheck.xml
    For Windows users it would be much a hassle to finish the same task. You generally should launch a Command Prompt (or PowerShell, or whatever these guys decide to name it in the future), and enter the following commands:
    Code:
    cd PATH_TO_THE_SCRIPT_FILE
    c:\python32\python.exe newpostscheck.py -o niftyhost -g newpostscheck.xml
    (Refer to the section below for what these bizarre switches stands for.)
    Then please open the newpostscheck.xml in the directory in which the script file is placed, with a text editor fully supporting UTF-8. In the file you would find lines like this:
    Code:
    <target name="username" key="niftyhost"><![CDATA['']]></target>
      <target name="enable" key="niftyhost"><![CDATA[True]]></target>
      <target name="password" key="niftyhost"><![CDATA['']]></target>
    (If you don't have lxml installed, the format of the XML elements would be different, and there won't be CDATA section inserted, but the basic structure is the same. If you don't use CDATA to wrap the text content, you need to escape "&" and a few other characters. Pay attention to the "key" attribute and make sure it's indeed "niftyhost" that you are editing when you read the XML file.)
    Basically in the "username" and "password" field, you should fill in your username and password enclosed in single quotes, like:
    Code:
    <target name="username" key="zemhost"><![CDATA['RichardGv']]></target>
      <target name="enable" key="zemhost"><![CDATA[True]]></target>
      <target name="password" key="zemhost"><![CDATA['MY_PASSWORD']]></target>
    Save the file, launch the Python script, and it's done!
    With the option -G you may generate a full configuration file and view all the settings you may change. You may modify the regular expressions with which the page matching is performed, configure custom commands to execute after a new post is discovered, localize the messages the script prints, or even add new forums to the list of forums the script currently supports (which requires a lot of work. though). I may write a better document describing all the available settings in the future.
  • Commandline arguments support. (argparse is awesome and foolproof, by the way.) Use the "--help" command switch to view an introduction about all supported commandline arguments.
    Code:
    usage: newpostscheck.py [-h] [-d] [-D] [-e TARGET [TARGET ...]]
                            [-E TARGET [TARGET ...]] [-o TARGET]
                            [-g FILE | -G FILE | -s]
                            [CONFIGURATION_FILE [CONFIGURATION_FILE ...]]

    Checks for new posts in various forums

    positional arguments:
      CONFIGURATION_FILE    path to the configuration file ("-" for stdin)

    optional arguments:
      -h, --help            show this help message and exit
      -d, --debug           enable debug mode
      -D, --no-debug        disable debug mode
      -e TARGET [TARGET ...], --enable TARGET [TARGET ...]
                            enable a target
      -E TARGET [TARGET ...], --disable TARGET [TARGET ...]
                            disable a target
      -o TARGET, --only TARGET
                            keep only a target enabled
      -g FILE, --genconf FILE
                            generate a basic configuration file ("-" for stdout)
                            and quit
      -G FILE, --genfullconf FILE
                            generate a configuration file containing all the
                            available settings ("-" for stdout) and quit
      -s, --list-targets    list supported target sites
    The environment variable NPC_OPTIONS (Well, it's called NPC since it's New-Posts-Check script, which has nothing to do with the alternative NPCs.) can be used to add default options to the script, e.g. NPC_OPTIONS='-d' turns debug mode on by the default. It's useful on very specific conditions and is placed there as a courtesy for the crazy programmers among you. Specfying path to the configuration directory in it or use syntax like "--" may cause unpredictable results (for me, not for the computer) that I cannot be responsible for. Do not play with fire in it, or you will burn your fingers. :D
  • Commands executed after new posts are discovered are now queued by default. So if you have specified a command that takes quite a long period of time to execute (e.g. mplayer), the script won't be throttled. Using the subprocess module may create more ideal results, yet it's beyond the scope of a simple Python script.
  • Due to HK's request, URL-specific HTTP header supported is introduced. Review config['headers_hosts'] for more information.
  • Gzip compression is now supported to save some bandwidth (and money!) for you. It just sits in the background working silently and you need not to worry.
  • Many other changes and enhancements that I'm tired to list. Writing README is more painful that writing the code itself...
Again, this script could be buggy since it's not tested enough.

I've uploaded the script to GitHub, and you can keep track of the latest development snapshots there. Well, actually what I am releasing all above are development snapshots, aren't they?
https://github.com/richardgv/newpostscheck

I will update the main thread tomorrow. Sleepy today. :)
Gentoo Linux User (w/ fvwm) / Loyal Firefox User / Owner of a Stupid Old Computer - My PGP Public Key

No man is an island, entire of itself; every man is a piece of the continent, a part of the main; if a clod be washed away by the sea, Europe is the less, as well as if a promontory were, as well as if a manor of thy friends or of thine own were; any man's death diminishes me, because I am involved in mankind; and therefore never send to know for whom the bell tolls; it tolls for thee.
-- Devotions Upon Emergent Occasions (1624), John Donn
Reply


Messages In This Thread
RE: Forum New Posts Notifier for NiftyHost - by RichardGv - 04-29-2011, 12:33 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How did you find Niftyhost? Serial Thrilla 21 4,678 06-29-2012, 07:26 AM
Last Post: Jennifer
  NiftyHost Server Monitor (created by Piotr GRD) Piotr GRD 21 11,931 01-18-2012, 05:12 AM
Last Post: Serial Thrilla
  OMG COLORS! A Niftyhost Production pspboy 12 3,855 01-18-2012, 05:01 AM
Last Post: Serial Thrilla
  NiftyHost Affiliate System MyDigitalpoint 4 1,799 10-09-2011, 01:12 PM
Last Post: cuckooz
Information How To Run A Board Forum Like myBB And SMF in Your Own PC [just for fun]! KSubedi 31 17,404 08-15-2011, 10:26 AM
Last Post: MyDigitalpoint
  Niftyhost (Forums) reaches 500 registered members Vanilla 36 7,359 06-26-2011, 06:28 AM
Last Post: micro

Forum Jump: