Coder Social home page Coder Social logo

add-web's People

Contributors

ertondev avatar marcben05 avatar superjavicon avatar xaviii03 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

petersimeth

add-web's Issues

Handle key inputs in cc.py with python

I don't know how to implement key inputs in my python program, help :)

I'm currently programming the Control Unit Monitor, or Control Center, to display important values that my bot works with. My idea is to make a selector to move across data in our database, and the way to do that was by using keys. Sadly, I don't know how to do that.

I've been reading the pynput module docs to find some information about this and I've tried lots of different things, but none worked as I expected.

The objective

The program should be able to call one function when w is pressed and a different one when s is pressed.

Configure and use database

The bot needs to start using information online so we must setup the postgreSQL db. I've deployed the db in a Heroku server and the API is working. We should "rewrite" the bot1.py files to work with the db.

Adapt flask code to the latest version of our API

app.py raises an ImportError when trying to import post, get and push functions that no longer exist

Because post, get and put no longer exist in psqlapi.py we must change this import code to import each function with its respective new name.

Change server name in code

I think we should change the name of the server in the website code to ADD instead of "A" del Discord. The original name isn't serious and now that the project is public we should keep this in mind. I will be doing this as soon as possible, but anyone can do it.

We didn't do this right in the bot files

We are treating ints as lists in the bot files...

When we did the update to support the database we forgot that we were no longer working with lists, but with individual values. I'm going to upload a version of the bot files where we haven't tried anything to fix the issue yet, this way we can easily fix the lists problem.

autodatabase.py fails to upload data to DB

For some reason autodatabase.py is raising errors when trying to upload data from our .txt files to DB. We have updated the users table from our DB and we need to use this file to reupload all the information.

Get the bot running 24/7

Once the bot is completely finished we should host it on a server...

Because we are hosting our database in Heroku, I think that hosting the bot there would be a good idea too.

I'm leaving here a link for a site that may be useful for this issue: https://medium.com/@linda0511ny/create-host-a-discord-bot-with-heroku-in-5-min-5cb0830d0ff2

At the moment we are still tweaking some of the new features as well as fixing some bugs.
You can see more in:

#8 - BOT connection to the PostgreSQL database.

BOT connection to the PostgreSQL database

It's time to connect our bot to the database

When I programmed the bot I thought of using .txt files as a database. This has worked fine but now we need to have this information online. This is why we must change all the code related to the .txt files and implement the API where it is needed.

What to know

We have already programmed different scripts to make this easier, this is a closed issue that may be useful:

#5 - Automatize database update process

There is some data that I would like to keep as .txt files (multas.txt, and other files related to the casino/ games), if you would like a more detailed description leave a comment.

The code that we should change is the one related to bolsa/ and profile/:

file = io.open("path/file.txt", "r") # r to read, w to write, a to append
file_content = file.readlines()
file.close()

This code got the lines of file.txt:

print(file_content[0])
>>> line_1
print(file_content[1])
>>> line_2
...
print(file_content[i])
>>> line_i+1

Basically the bot wrote or updated data in files to then read that same information.


You will also have to change the code where the bot creates new profiles:

create_profile = os.makedirs(f"profile/{ctx.author.id}_profile", exists_ok = True)

You can look at this in line 899 (29/11/2021 9:50, 11/29/2021 9:50)

How to do it

The new code should use our API located inside the web/ folder. This was programmed by @MarcBen05
Import it as a module:

from web.psqlapi import *

Then you can start rewriting the code! :)
LEAVE A COMMENT IF YOU HAVE ANY QUESTION

Automatize database update process

We should automatize the process of uploading the bot's information to the database

To do this we should create a script with python that does this automatically.

Where to find the information

All the information that must be updated to the database is on the add-web/profile/ and add-web/bolsa/.
Some of the information in these files are outdated but should help to start coding the script.

The script should be able to be executable at any time and it would update all the values of accounts and in-game values.

You can use the psqlapi.py file to import useful functions from there. These functions will allow you to connect with the database. Take into account that you will also need the environment variables for this so send me a msg as soon as you want to test the code.

How to do it

The script should be properly written to make it easily updatable in the future. To make the psqlapi.py script run properly you will need to create a .env file in the same folder as the script (add-web/web/) and write on it the environmental variables used for:

HOST = ...
DBUSER = ...
PASS = ...
DBNAME = ...

Import all the modules at the beginning of the script.

import psqlapi.py

or

from psqlapi.py import ...

In case you don't create the automation file inside of the add-web/web/ folder and do it in add-web/ instead:

import web.psqlapi.py

or

from web.psqlapi.py import ...

I would recommend reading psqlapi.py before starting to write the automation script.

You will also need to use the io module to read .txt files using the open() function.

import io

Here is an example for reading files:

file = io.open("path/to/file/file.txt", 'r')
file_lines = file.readlines()
file.close()

Remember to always close the file, then you can print each line of the file, here is an example:
file.txt

ABC
CBA
123

Your script

for i in range(3):
    print(i + 1, file_lines[i])
    # 0, 1, 2

The output should look like this:

1    ABC
2    CBA
3    123

If you have any issue with the explanation leave a comment :)

Setup passwords for accounts

Passwords will keep accounts' settings private.

Passwords aren't something crucial for the project, but if we add functions to delete accounts, then that should be protected.

First our database and API must be adapted and then .registro in bot.py has to be updated to support the input of the password but in a private way. (Probably through MD)

Flask app.py ImportError

Flask raises an error when executing app.py.

Error message:
Error: While importing 'app', an ImportError was raised

I think this has something to do with flask being unable to import the libraries from venv. If anyone knows how to fix this issue, please send a Pull request. It works if you download all the libraries in your computer but doesn't if you don't. The idea is that flask gets the libraries from the venv.

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.