Giter Site home page Giter Site logo

fto-scraper's Introduction

scrape_fto.py Grabs data from faerytailonline webpage for use in a csv in the following format:

MM/DD/YY-HH, Population, Birth Queue Size, Pregnant Mothers

where the time is UTC. HH is in 24 hour format

fto-graph.py uses the cumulative output from scrape_fto.py to generate a graph of the data.

Image of output graph

Requirements

Python2.7 or Python3.3+
Bash
beautifulsoup4 (python library)
requests (python library)
matplotlib (python library)
pandas (python library)

Installation

For Debian/Ubuntu you can install:

sudo apt-get install python3 python3-pip

Inside a virtualenv, you should install:

pip install beautifulsoup4 requests matplotlib pandas

Or use pip install --user

If your pip version is older than 9.0, then your pip may require additional packages to build matplotlib:

sudo apt-get install libfreetype6-dev python3-dev

And then rerun pip

Usage

scrape_fto.py

./scrape-fto.py

Queries fto and echos the formatted string

append_csv.sh

Calls the above python script and appends the output to a csv and creates headers if empty. This script should be called by crontab at regular intervals and the output csv should be accessable via http

e.g.

    ./append_csv.sh output.csv

A crontab entry might look like

    0 0,12 * * * /dir/append_csv.sh /var/www/fto-stats.csv

which runs the script twice per day at 12AM / 12PM where dir is the directory for append_csv.sh AND scrape_fto.py

truncate_csv.sh

Truncates the result from append_csv.sh, to the last 6 months of data to the beginning of the last 6th month. This script is called inside from append_csv.sh and creates a csv file with the same name as the output of appen_csv in the same directory, with _6months.csv appended to to the end.

Output

    Date,Population,Birth Queue,Pregnant Mothers
    02/15/16-08,311,152,3

Once the csv is accessable via http, it can be linked into a google doc, and graphs can be applied to the data

fto-graph.py

Graphs the csv data and outputs an png of the graph::

./fto-graph.py example/fto-stats.csv output.png

fto-scraper's People

Contributors

brycepg avatar joodicator avatar

Stargazers

 avatar

Watchers

 avatar  avatar

fto-scraper's Issues

Raw pregnant mothers offset by +2 since late February 2017.

fto_graph.py automatically adjusts for a bug where the reported number of pregnant mothers is 1 greater than the true value. I've been told that this is because a mother was killed while pregnant.

It recently came to my attention that another pregnant mother was killed between 2017-02-24 (the last time that the population rose while the number of pregnant mothers was 2) and 2017-02-28 (when the mother's murderer was reported to have been killed). After this, it can be seen that the number of pregnant mothers reported by the game has never fallen below 2.

This means that the number of pregnant mothers being graphed is now incorrect. This could be fixed simply by applying a piecewise constant offset to the data, based on the date of collection, but I'm not sure if this is the best solution.

With 1 data point, fto-graph.py issues warning and produces empty graph

For example, with fto.csv having these contents:

Date,Population,Birth Queue,Pregnant Mothers
06/28/16-03,297,318,6

This is the console output:

$ ./fto-graph.py fto.csv
/usr/lib/python2.7/dist-packages/matplotlib/axes/_base.py:2782: UserWarning: Attempting to set identical left==right results
in singular transformations; automatically expanding.
left=736143.125, right=736143.125
  'left=%s, right=%s') % (left, right))

And this is output.png:
output

Other relevant information:

$ python --version
Python 2.7.10rc1
$ python -c 'print __import__("matplotlib").__version__'
1.5.2rc2
$ python -c 'print __import__("pandas").__version__'
0.18.0+git114-g6c692ae

The expected behaviour would be that it produces a graph with a single data point, or at least does not write a warning to the console. I realise this isn't a very important issue, but I thought it would be good to note it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.