Friday, October 18, 2013

Configuration for Bing! Rewards Automation script

This is a configuration manual for Bing! Rewards Automation config.xml

Example

<configuration>
    <general 
            betweenQueriesInterval="2.0" 
            betweenQueriesSalt="3.0"
            betweenAccountsInterval="40.0" 
            betweenAccountsSalt="45.0" />

    <accounts>
        <account type="Facebook" disabled="false">
            <login>john.smith@gmail.com</login>
            <password>xxx</password>
        </account>
        <account type="Facebook" disabled="true">
            <login>blabla@mail.com</login>
            <password>xxx</password>
        </account>
        <account type="Live" disabled="false">
            <login>gogo@hotmail.com</login>
            <password>xxx</password>
        </account>
        <account type="Live" disabled="false">
            <login>hoho@hotmail.com</login>
            <password>xxx</password>
        </account>
    </accounts>

    <events>
        <onError>
            <retry interval="5" salt="3.5" count="3" />
            <notify cmd="/home/BingRewards/bin/notify/onError.sh %a %p %r %P %l %i %e" />
        </onError>
        <onComplete>
            <retry if="%p lt 16" interval="5" salt="3.5" count="3" />
            <notify if="%l gt 3000"
                    cmd='/home/BingRewards/bin/notify/onComplete_reached.sh %a %p %r %P %l %i "reached %l Life Credits"' />
            <notify if="%p ne 16"
                    cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />
            <notify if="%P gt 475"
                    cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />

            <account ref="Live_gogo@hotmail.com">
                <retry if="%p lt 16" interval="5" salt="3.5" count="3" />
                <notify if="%l gt 750"
                        cmd='/home/BingRewards/bin/notify/onComplete_reached.sh %a %p %r %P %l %i "Gold with %l Life Credits"' />
                <notify if="%p ne 16"
                        cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />
                <notify if="%P gt 475"
                        cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />
            </account>
            <account ref="Facebook_john.smith@gmail.com">
                <retry if="%p lt 31" interval="5" salt="3.5" count="3" />
                <notify if="%l gt 10000"
                        cmd='/home/BingRewards/bin/notify/onComplete_reached.sh %a %p %r %P %l %i "reached %l Life Credits"' />
                <notify if="%p ne 31"
                        cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />
                <notify if="%P gt 475"
                        cmd="/home/BingRewards/bin/notify/onComplete.sh %a %p %r %P %l %i" />
            </account>
        </onComplete>
        <onScriptComplete>
            <notify cmd="/home/BingRewards/bin/notify/onScriptComplete.sh mail" />
        </onScriptComplete>
        <onScriptFailure>
            <notify cmd="/home/BingRewards/bin/notify/onScriptFailure.sh mail" />
        </onScriptFailure>
    </events>
</configuration>

Man

Section (optional) general
==========================

    Defines general configuration

    Supported attributes:

        betweenQueriesInterval  - (optional) - (double) - how many seconds the script should wait between queries
                                             - Defaults to 1 second

        betweenQueriesSalt      - (optional) - (double) - up to how many seconds to wait on top of _betweenQueriesInterval_ (rand(0, salt))
                                             - Defaults to 3 seconds

        betweenAccountsInterval - (optional) - (double) - how many seconds the script should wait after completing an account and before loggining into the next account
                                             - Defaults to 30 seconds

        betweenAccountsSalt     - (optional) - (double) - up to how many seconds to wait on top of _betweenAccountsInterval_ (rand(0, salt))
                                             - Defaults to 35.5 seconds


Section (optional) [configuration.events]
=========================================

    Defines how the script should react on events.

    Supported events: { onError, onComplete, onScriptComplete, onScriptFailure }

    Note: this section and all its subsections are applied per account
          for events { onError, onComplete }
          and only once for events { onScriptComplete, onScriptFailure }


Section (optional) [configuration.events.onError]
=================================================

    Defines what the script should do when an error occurs during processing an account. That
    can be any kind of error which results in generating result/error_*.html file
    (i.e. authorization, unexpected server response, etc.)

    Supported subnodes:

        retry   - (optional) - see EVENTS.RETRY
        notify  - (optional) - see EVENTS.NOTIFY
        account - (optional) - see EVENTS.ACCOUNT

    Note: multiple _onError_ sections will be processed as one


Section (optional) [configuration.events.onComplete]
====================================================

    Defines how the script should behave when it completes processing an account.

    Supported subnodes:

        retry   - (optional) - see EVENTS.RETRY
        notify  - (optional) - see EVENTS.NOTIFY
        account - (optional) - see EVENTS.ACCOUNT

    Note: multiple _onComplete_ sections will be processed as one


Section (optional) [configuration.events.onScriptComplete]
==========================================================

    A special event which occurs only once when the script finishes executing. A good example of
    utilizing this event is:

        1. In _onError_ and _onComplete_ append information to a log file.
        2. In _onScriptComplete_ send that big log file over email.

    Supported subnodes:

        notify - (required) - see [configuration.events.onScriptComplete.notify]

    Note: multiple _onScriptComplete_ sections will be processed as one


Section (optional) [configuration.events.onScriptFailure]
==========================================================

    A special event which occurs only once and if the script fails with exception some time after
    successfully loading the config.

    Supported subnodes:

        notify - (required) - see [configuration.events.onScriptFailure.notify]

    Note: multiple _onScriptFailure_ sections will be processed as one


Section (optional) [configuration.events.onScriptComplete.notify]
=================================================================

    Describes what action to take on event.
    More than one _notify_ can be specified.

    Supported attributes:

        cmd - (required) - shell command to run on event

                Note: this attribute is different from EVENTS.NOTIFY.cmd
                    _Format Specifiers_ are not supported here.


Section (optional) [configuration.events.onScriptFailure.notify]
=================================================================

    Describes what action to take on event.
    More than one _notify_ can be specified.

    Supported attributes:

        cmd - (required) - shell command to run on event

                Note: this attribute is different from EVENTS.NOTIFY.cmd
                      _Format Specifiers_ are not supported here.

                Note: 1 argument will be passed to _cmd_ which is exception string


Section (optional) EVENTS.ACCOUNT
=================================

    Overrides the script notification behavior for an account. If the behavior is not
    overridden, global notification behavior is applied.

    Supported attributes:

        ref - (required) - a reference to an account of a format:

                                accountType_accountLogin

                           ex. Facebook_john.smith@gmail.com

    Supported subnodes:

        retry  - (optional) - see EVENTS.RETRY
        notify - (optional) - see EVENTS.NOTIFY


Section EVENTS.RETRY
====================

    Tells the script it should retry processing an account.

    Supported attributes:

        if       - (optional) - See EVENTS.{RETRY|NOTIFY}.IF
        interval - (required) - (double) - how many seconds the script should wait between retries
        salt     - (optional) - (double) - up to how many seconds to wait on top of interval (rand(0, salt))
        count    - (required) - (unsigned) - how many times to retry


Section EVENTS.NOTIFY
=====================

    Defines the notification behavior of the script. The notification will be triggered
    only once per all retries on an account.

    More than one _notify_ can be specified.

    Supported attributes:

        if  - (optional) - see EVENTS.{RETRY|NOTIFY}.IF

        cmd - (required) - an external command to execute on event. _Format Specifiers_ can be
                passed as arguments. See _Format Specifiers_
                subsection.


Section EVENTS.{RETRY|NOTIFY}.IF
================================

    This section sets a condition which must be evaluated to TRUE in order for the script
    to trigger retry behavior (see EVENTS.RETRY).

    Format:
    ~~~~~~~

        "specifier comparison_operator value"

        _if_ statement consists of three parts:

            specifier           - identifies which value of the script evaluated thus far
                or _lhs_          should be compared. See _Format Specifiers_.

            comparison_operator - how the _specifier_ should be compared to the _value_.
                or _op_           See _Comparison Operators_ below.

            value               - the value which the _specifier_ should be compared to
                or _rhs_


    Comparison Operators:
    ~~~~~~~~~~~~~~~~~~~~~

        As per http://www.w3.org/TR/2008/REC-xml-20081126/#syntax

            (<) must not appear in their literal form, except when used as markup delimiters,
            or within a comment, a processing instruction, or a CDATA section.

        thus, in order to be consistent, integer comparison operators from "man test" are used
        (with one exception that "-" sign is omitted).

        From: http://unixhelp.ed.ac.uk/CGI/man-cgi?test

            INTEGER1 -eq INTEGER2
            INTEGER1 is equal to INTEGER2

            INTEGER1 -ge INTEGER2
                INTEGER1 is greater than or equal to INTEGER2

            INTEGER1 -gt INTEGER2
                INTEGER1 is greater than INTEGER2

            INTEGER1 -le INTEGER2
                INTEGER1 is less than or equal to INTEGER2

            INTEGER1 -lt INTEGER2
                INTEGER1 is less than INTEGER2

            INTEGER1 -ne INTEGER2
                INTEGER1 is not equal to INTEGER2


    Example:
    ~~~~~~~~

        "%r ge 3"    - 3 or more retries were made
        "%p lt 50"   - points (earned during this session) is greater than or equal to 50
        "%l gt 1000" - lifetime credits is greater than 1000


Format Specifiers
=================

    This section describes format specifiers.

    First column  - specifier

    Second column - where the specifier is applicable to (as one capital letter type)

                    Supported types:

                        C - EVENTS.NOTIFY.cmd
                        E - events.onError.notify.cmd (that type includes everything from C type)
                        I - EVENTS.{RETRY|NOTIFY}.IF

    Third column  - description

    %a - C  - account name and type (ex. Facebook - john.smith@gmail.com)
    %e - E  - error, which caused that notification
    %i - C  - prints corresponding _if statement_ or "(None)"
    %l - CI - lifetime credits
    %p - CI - points earned during this session
    %P - CI - total reward points available
    %r - CI - number of retries made during this session

38 comments:

  1. Nice work done, but documentation is not clear enough for a non PYTHON or for the matter non techie's to try out your automator. All the best !

    ReplyDelete
    Replies
    1. Thanks. The only thing which really needs to be configured is in config.xml. There is no need to have Python skills to tune it. Also, the most of those who have tried it are not tech guys to my understanding. But thanks for the feedback

      Delete
  2. Regarding the configuration file, seems a bit of a pain to have to set the account login in 2 spots (account login/pw section as well as using it for the account reference. Also, rather than hardcoding the notify command to a full path, why not set a path variable and modify all the commands to use the variable/notify/shellscript.sh?

    Was able to configure V2 of the script without much issue but it stopped working. Trying to get V3 working but not having much success. Set FB to disabled, have 1 Live account enabled, set the login/pw, changed the notify command paths as well as onScriptComplete and onScriptFailure to be correct for my MacBook Pro but when i execute using ./main.py --verbose -f config.xml via Terminal on Mac OS 10.7.5 with Python 2.7.1 it starts the script and comes back with

    Full log:
    ---------
    Empty log
    onScriptFailure: -mail

    I need more tea and some ibuprofen now.

    ReplyDelete
    Replies
    1. You don't have to set an account under _events_ section. From the documentation above:

      Section (optional) EVENTS.ACCOUNT
      Overrides the script notification behavior for an account. If the behavior is not
      overridden, global notification behavior is applied.

      The global behavior in the example above comes right after _onComplete_ - one _retry_, three _notify_ sections.

      I agree configuring the script can be a challenge especially for a non tech person, but hey, that's the free stuff which I develop and also I'm here to help - just ask.

      I've considered adding environment variables support into the script, but that will come later (probably). I don't want to support arbitrary variables yet. I began writing Bing! Rewards Automation script with one thought in mind which was to automate the routine. I don't see specifying right parameters in config.xml once as a routine.

      Finally, if you want the same to version 2 behavior, without events (which is retries and notifications), just leave accounts section (as it was in v2) - I have just tested and that worked to the point of

      https://github.com/sealemar/BingRewards/issues/8

      which is completely different issue which I will be looking at.

      Version 3 is completely backward compatible with version 2.

      One last debugging thought which I will add to the Troubleshooting section a little bit later - if something doesn't work and the script returns

      onScriptFailure: blablabla

      just comment that onScriptFailure section out and run the script again - it will output a more verbose information.

      And, please, read the documentation more carefully, almost all sections of config.xml are optional which means you don't have to specify those.

      Delete
    2. I want to emphasize once again - a lot of sections in config.xml are optional meaning you don't have to have them in your config.xml.

      Delete
    3. I must need a "Dummies" guide then. I'm learning Python but must not have enough of the basics down yet.

      Taking the default config.xml, I turn disabled to true for the 2 Facebook entries and the last Live entry, leaving only the 1st entry for Live enabled. I use the login/pw, replacing gogo@hotmail.com. Try executing and get

      ConfigError: Corresponding account is not found for EVENTS.ACCOUNT.ref = [Live_gogo@hotmail.com]

      I update the events section replacing 'Live_gogo@hotmail.com' with 'Live_myemail@hotmail.com' (myemail@hotmail.com is an example here, not what I really have entered).

      Execute again and get:
      For: Live - myemail@hotmail.com

      --------------------------------------------------------------------------------
      /bin/sh: /home/BingRewards/bin/BingRewards/notify/onScriptFailure.sh: No such file or directory

      The path /home/BingRewards/bin/BingRewards/notify is not correct.

      Take out the section from the config so it contains the XML declaration, and section including but nothing more. Maybe I was mistaken that when you said the events were optional and V2 only had those two sections that could be removed from the config. I think it is required as it generates several errors on execution:

      Traceback (most recent call last):
      File "./main.py", line 260, in
      EventsProcessor.onScriptFailure(config, e)
      File "./main.py", line 258, in
      __run(config)
      File "./main.py", line 184, in __run
      __processAccount(config, reportItem, account.password)
      File "./main.py", line 161, in __processAccount
      earnRewards(config, reportItem, accountPassword)
      File "./main.py", line 48, in earnRewards
      rewards = bfp.parseFlyoutPage(bingRewards.requestFlyoutPage(), bingCommon.BING_URL)
      File "./pkg/bingFlyoutParser.py", line 99, in parseFlyoutPage
      s = page.index('< div id="messageContainer">')
      ValueError: substring not found

      I knew this wasn't going to be a simple fix when my V2 gave me the following error this morning: /bin/sh: /home/BingRewards/bin/BingRewards/notify/onScriptFailure.sh: No such file or directory

      Delete
    4. Dean, I wrote above about that issue which caused a traceback. The issue was reported a couple of hours ago and can be tracked here:

      https://github.com/sealemar/BingRewards/issues/8



      /home/BingRewards/bin/BingRewards/notify/onScriptFailure.sh

      should point to the script which you want to use if Bing! Rewards Automation fails. As for now that should be an absolute path to the script (executable name can be different. onScriptFailure.sh is just an example. It can be any kind of executable). You don't have to use it, you may comment onScriptFailure section out. In fact, if you don't use the script with cron, then (probably) you don't need it, because everything will be outputted to STDOUT anyways. Events exist to automate retries and to trigger extra behavior.

      You say:

      ConfigError: Corresponding account is not found for EVENTS.ACCOUNT.ref = [Live_gogo@hotmail.com]

      That's right, just remove configuration-events-onComplete-account-ref[Live_gogo@hotmail.com] section. Again - account subsection under events, such as onComplete CAN BE specified if, for example, you have a Facebook account which you know for sure earns you 30 points a day and then several Live accounts which earn you 15 points a day each. Then you create a global events.onComplete with notify.if="%p lt 15" (which will be triggered if the script earns you less than 15 points) and then you create events.onComplete.account.ref=[Facebook_mylovelyfbacc@gmail.com] with notify.if="%p lt 30" which will override global behavior and will trigger notify only for this particular account if the script earns you less than 30 points for that account. Is that clear?

      Delete
    5. Downloaded the latest this morning, removed the onComplete section and we have success! Excellent work! Thank you! Now that this is working, I may set up a cron job to run the script at a "random" time within a certain hour from my hosting provider.

      Delete
    6. Sounds cool! Tell me how it all works out.

      Delete
  3. Although I believe I have configured the config XML properly, I keep getting this error

    ConfigError: Corresponding account is not found for EVENTS.ACCOUNT.ref = [myemail@msn.com]

    Any ideas?

    ReplyDelete
    Replies
    1. EDIT: I made an error on the config file that I fixed. But unfortunately I am now getting the same error as Dead where the script returns

      Full log:
      ---------
      Empty log
      onScriptFailure: -mail

      Delete
  4. Guys, everybody who had issues with the script on 10/25/2013, git pull Bing! Rewards Automation script version 3.0.3 that fixes the script failure caused by the change in by Bing! flyouts.

    ReplyDelete
    Replies
    1. more on the specifics of the issue here:

      https://github.com/sealemar/BingRewards/issues/8

      Delete
    2. Thanks Sergey,

      I just updated the instance on my machine and it's working great. I no longer get zero output. I truly appreciate all the work you put into this.

      Delete
  5. Bing! Rewards Automation script version 3.1:

    Added to config.xml:

    configuration.general.betweenAccountsInterval (optional)
    configuration.general.betweenAccountsSalt (optional)

    Refer to the documentation above for the details

    ReplyDelete
  6. Bing! Rewards Automation script: Unix Cron

    http://sealemar.blogspot.com/2013/10/bing-rewards-automation-script-unix-cron.html

    ReplyDelete
  7. FYI, Bing may have changed authentication once again breaking the script. I keep getting "onScriptFailure" errors. I have changed nothing on my end and my logs state that it's been working fine since the release of version 3.0 up until yesterday.

    ReplyDelete
    Replies
    1. Bug Opened:
      https://github.com/sealemar/BingRewards/issues/9

      Delete
    2. Fixed in version Bing! Automation Script v.3.1.1. git pull and enjoy

      Delete
  8. This comment has been removed by the author.

    ReplyDelete
  9. I'm having the same problem as Dean.
    ConfigError: Corresponding account is not found for EVENTS.ACCOUNT.ref = [my@email.com]

    there's something unclear here.
    Where exactly are you saying to put my email account?

    I'm setting it up for email notification but that's beside the point atm because it isn't getting that far in the process.
    config sample here: http://pastebin.com/JXeJ9DNd
    it's exactly what I'm using except for the account credentials


    I could be wrong but, also, this config example on this page is correct while the github config.xml is not. the repo has an extra BingRewards in the path:

    this page:
    notify cmd="/home/BingRewards/bin/notify/onError.sh

    github:
    notify cmd="/home/BingRewards/bin/BingRewards/notify/onError.sh

    ReplyDelete
    Replies
    1. Check line 31 in your config and the description of
      Section (optional) EVENTS.ACCOUNT
      Do you see how your config doesn't follow the documentation?

      Also, if you have just one account, there is no need to have that optional section.

      To answer your last question, read
      Section EVENTS.NOTIFY
      of the documentation. Do you see what cmd attribute is meant to be? It is a path to whatever executable you want to run. Do you have that path and the executable on your machine?

      Delete
  10. How do I make it work on windows machine? I have python installed. I suppose change config file to point to absolute path from unix style /home?

    ReplyDelete
    Replies
    1. on Windows you probably don't want to have event hooks. Just comment out the entire events section

      Delete
    2. Thanks for your quick reply Sergey....My configuration file is below for other googlers and it works








      raOne@gmail.com
      mypassword


      blabla@mail.com
      xxx


      gogo@hotmail.com
      xxx


      hoho@hotmail.com
      xxx




      However i am getting AuthenticationError:
      Authentication has not been passed:

      I have double checked the password and I am using the first facebook entry as posted in above configuration. Any suggestions?

      Thanks!

      Delete
    3. Blogspot doesn't show tags correctly. Your config wasn't posted. Regarding your question - open an issue on github with detailed description and logs - https://github.com/sealemar/BingRewards

      Delete
    4. There is no log when I tried again

      C:\Users\XXX\Desktop\BingRewards-master\pkg\bingRewards.py

      Enter

      C:\Users\XXX\Desktop\BingRewards-master\pkg\bingRewards.py

      Enter

      C:\Users\XXX>

      I have removed events section completely from config.

      xml version="1.0"

      configuration
      general
      betweenQueriesInterval="10.0"
      betweenQueriesSalt="5.0"
      betweenAccountsInterval="300"
      betweenAccountsSalt="600" />

      accounts
      account type="Facebook" disabled="false"
      login XXX@gmail.com<login
      passwordXXX3password
      account
      accounts
      configuration

      Thanks again for your help!

      Delete
    5. So what is your question? Can you open an issue on GitHub with your question, detailed description and python version you use?

      Delete
  11. hey Sergey, im JUST getting into coding and fairly new at most of this, i read through the explanation of commands, but i cannot comprehend how to instruct the config to go back and start binging for a second account? everything ive tried either errors or stops after my primary account.

    ReplyDelete
    Replies
    1. You don't need to do anything special. All the accounts under accounts tag are searched automatically.

      Delete
  12. hey Sergey. . . Good Work.
    I cloned the latest version from your repo and made the necessary configurations in the config.xml.
    However, i still face the following issue
    2014-10-24 17:43:38.9 - script started
    --------------------------------------------------------------------------------


    For: Facebook - myMailId@gmail.com

    --------------------------------------------------------------------------------

    Full log:
    ---------
    Empty log
    onScriptFailure: -mail

    I noticed in one comment above that one person faced the same issue. But i was not able to get the solution in his case. Please help me out here.

    ReplyDelete
  13. The script is running great for me, but I have a quick question. Does it take into account double points days or should I increase the retry threshold under onComplete in the config.xml from 16 to 31 in order to accommodate that? Thanks!

    ReplyDelete
    Replies
    1. it does take into account double point days

      Delete
    2. Awesome, thanks for the quick response!

      Delete
  14. i am getting ConfigError: EVENTS.ACCOUNT.ref is not found
    i am using raspberry pi

    ReplyDelete
    Replies
    1. Have you try doing Ctrl+F for "is not found" right on this page? People were having similar issues all of which were addressed.

      Delete
  15. Hi, the script has been working for me except when it finishes the searches and gives a SyntaxError: invalid syntax on line 3 of onComplete.sh.

    ReplyDelete
  16. Newbie question here. How do I install this on my Raspberry Pi? I've installed it on my Mac, but I can't figure out how to make it run on my Pi.

    ReplyDelete