项目作者: 30mb1

项目描述 :
Chat log with the ability to search by date and also special features for registered users.
高级语言: CSS
项目地址: git://github.com/30mb1/Chat-parser.git
创建时间: 2017-09-21T12:27:49Z
项目社区:https://github.com/30mb1/Chat-parser

开源协议:

下载


Chat parser

Chat parser is a tool for collecting messages from wex.nz chat and convenient search on them by date or nickname. The program provides a set of tools for analyzing the chat and saving useful information.

Getting started

Requirements

  • Python 3
  • MongoDB database 3.2+
  • Apache/Nginx

Installation

Clone repository with —recursive flag for downloading a submodule.

  1. git clone --recursive https://github.com/30mb1/chat-parser.git
  2. cd chat-parser

Create virtual environment and install requirements.

  1. virtualenv -p python3 venv
  2. source venv/bin/activate
  3. pip install -r requirements.txt

Set up proxy server (example for nginx):

  • Create new configuration file in save it in /etc/nginx/sites-available/your_app.conf

    Content of your_app.conf:

    1. server {
    2. listen 80;
    3. server_name some_domain.com;
    4. root /path/to/your_app;
    5. access_log /path/to/your_app/logs/access.log;
    6. error_log /path/to/your_app/logs/error.log;
    7. location / {
    8. proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    9. proxy_set_header Host $http_host;
    10. proxy_redirect off;
    11. if (!-f $request_filename) {
    12. proxy_pass http://127.0.0.1:8000; # you can choose another port
    13. break;
    14. }
    15. }
    16. }
  • Create symbol link for sites-enabled:

    1. sudo ln -s /etc/nginx/sites-available/your_app.conf /etc/nginx/sites-enabled/
  • Check configuration for mistakes:

    1. nginx -t
  • If it is ok, reload nginx.

    1. service nginx reload

Now you can run application locally with gunicorn, using nginx for handling external requests and redirecting them.

Setting up

Run parsing module

Go to application’s directory and activate virtual environment

  1. cd chat-parser
  2. source venv/bin/activate

Run module, that collect messages from chat and store them in database. Don’t forget to start mongodb. If you have non-standard configuration of access, you can configure it usage in database.py .

  1. screen chat-parser.py # screen allows us to run program in a separate window, so that it works as a daemon

At the moment, chat-parser configured for collecting messages from wex.nz via websocket.

Create accounts for admins

Create accounts for admins (only users with accounts can use all features):

  1. python accounts.py -n 10 # will create 10 accounts with logins admin1 ... admin10 and random passowords

Write given accounts credentials, you will not be able to retrieve it later (only by manual access to db). Note that module tries to create logins in form admin1…N and if it is already taken it won’t do anything, so if you want to create more accounts later, use -f flag to set number to start numerating from:

  1. python accounts.py -n 5 -f 10 # will create accounts with logins admin10...admin15

Example:

  1. > python account.py -n 3
  2. admin0 / 2I442ZIOGA
  3. admin1 / QK6HM3YJJT
  4. admin2 / 5CT3KZBY83
  5. > python account.py -n 3 # trying to create 3 more accounts without flag
  6. admin0 is already taken
  7. admin1 is already taken
  8. admin2 is already taken
  9. > python accounts.py -n 2 -f 3 # now using -f flag
  10. admin3 / FC5QR83L7D
  11. admin4 / YFY3G9B0C6

Run

Now, when we configured everything, we can run our application

  1. cd chat-parser
  2. source venv/bin/activate
  3. # choose port, that we used in nginx .conf file earlier
  4. gunicorn app:app -b 127.0.0.1:8000 -w 8 --threads 8 # you can run it in screen too
  5. # you can set another number of workers or threads, depenging on your system characteristics
  6. # more detailed info you can find for example here
  7. # http://docs.gunicorn.org/en/stable/settings.html

You can check it locally or from external address that we specified in .conf file.

How to use it

Users without accounts can only view history of chat, using date/nickname filter. There 3 separate tabs for channels of wex.nz

http://storage9.static.itmages.com/i/17/1020/h_1508493240_7177178_787e403dbf.png

After login you get access to all features of app:

  • Adding messages to favourite
  • Downloading messages in csv format (it select all messages from current period)
  • Commenting messages on

Note, that favourite is common to everyone, so admins can share useful information.

That how panel looks like for admin

http://storage6.static.itmages.com/i/17/1020/h_1508494105_7416409_73a7f9f8c8.png

Also, some new tabs appear

  • Tabs for favourite messages
  • Tab for admins log (history of all admins activity)
  • Tab for changing system username (some unique inner identifier, not login)