~josealberto4444/apodnasabot

91e0ec76682157455fa8c40d84c535b26fb959fa — José Alberto Orejuela García 2 years ago 394e5e8
Read API key from config file
6 files changed, 97 insertions(+), 1 deletions(-)

A Pipfile
A Pipfile.lock
M README.md
A api.py
M init.sh
A start.sh
A Pipfile => Pipfile +12 -0
@@ 0,0 1,12 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
configparser = "*"

[requires]
python_version = "3.7"

A Pipfile.lock => Pipfile.lock +29 -0
@@ 0,0 1,29 @@
{
    "_meta": {
        "hash": {
            "sha256": "787a9af6a082f9ce972b3c5bd16222516bc7dd44fdad5f8e57dadc30920973b3"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.7"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {
        "configparser": {
            "hashes": [
                "sha256:45d1272aad6cfd7a8a06cf5c73f2ceb6a190f6acc1fa707e7f82a4c053b28b18",
                "sha256:bc37850f0cc42a1725a796ef7d92690651bf1af37d744cc63161dac62cabee17"
            ],
            "index": "pypi",
            "version": "==3.8.1"
        }
    },
    "develop": {}
}

M README.md => README.md +11 -1
@@ 36,10 36,20 @@ Do you want to contribute to the code? Glad to hear it, that's the purpose of pu

# Installation

Recreate the configuration files needed by the programme
For running this bot, you will need

- Python 3
- Python `pipenv`

Execute the initialization script:

    $ ./init.sh

This will do the following steps:

1. Create the configuration file `config.cfg` if it does not exist.
2. Create the python virtual environment if it's not created yet.





A api.py => api.py +21 -0
@@ 0,0 1,21 @@
# Copyright © 2019 José Alberto Orejuela García (josealberto4444)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import configparser

config = configparser.ConfigParser()
config.read('config.cfg')
api_key = config['NASA_API']['api_key']
print(api_key)

M init.sh => init.sh +6 -0
@@ 18,3 18,9 @@
if [ ! -f "config.cfg" ]; then
    cp "config.cfg.new" "config.cfg"
fi

if [ "$1" = "dev" ]; then
    pipenv install --three --dev --skip-lock
else
    pipenv install --three --ignore-pipfile
fi

A start.sh => start.sh +18 -0
@@ 0,0 1,18 @@
#!/bin/sh

# Copyright © 2019 José Alberto Orejuela García (josealberto4444)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

pipenv run python api.py