mirror of
https://gitlab.com/2-chainz/2-chainz-twitter-bot.git
synced 2025-07-27 08:31:36 +00:00
gave tweeter its own function
This commit is contained in:
4
.funcignore
Normal file
4
.funcignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.git*
|
||||||
|
.vscode
|
||||||
|
local.settings.json
|
||||||
|
test
|
131
.gitignore
vendored
Normal file
131
.gitignore
vendored
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
# Byte-compiled / optimized / DLL files
|
||||||
|
__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
|
|
||||||
|
# C extensions
|
||||||
|
*.so
|
||||||
|
|
||||||
|
# Distribution / packaging
|
||||||
|
.Python
|
||||||
|
build/
|
||||||
|
develop-eggs/
|
||||||
|
dist/
|
||||||
|
downloads/
|
||||||
|
eggs/
|
||||||
|
.eggs/
|
||||||
|
lib/
|
||||||
|
lib64/
|
||||||
|
parts/
|
||||||
|
sdist/
|
||||||
|
var/
|
||||||
|
wheels/
|
||||||
|
pip-wheel-metadata/
|
||||||
|
share/python-wheels/
|
||||||
|
*.egg-info/
|
||||||
|
.installed.cfg
|
||||||
|
*.egg
|
||||||
|
MANIFEST
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
# Usually these files are written by a python script from a template
|
||||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
|
*.manifest
|
||||||
|
*.spec
|
||||||
|
|
||||||
|
# Installer logs
|
||||||
|
pip-log.txt
|
||||||
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
|
# Unit test / coverage reports
|
||||||
|
htmlcov/
|
||||||
|
.tox/
|
||||||
|
.nox/
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
.cache
|
||||||
|
nosetests.xml
|
||||||
|
coverage.xml
|
||||||
|
*.cover
|
||||||
|
.hypothesis/
|
||||||
|
.pytest_cache/
|
||||||
|
|
||||||
|
# Translations
|
||||||
|
*.mo
|
||||||
|
*.pot
|
||||||
|
|
||||||
|
# Django stuff:
|
||||||
|
*.log
|
||||||
|
local_settings.py
|
||||||
|
db.sqlite3
|
||||||
|
|
||||||
|
# Flask stuff:
|
||||||
|
instance/
|
||||||
|
.webassets-cache
|
||||||
|
|
||||||
|
# Scrapy stuff:
|
||||||
|
.scrapy
|
||||||
|
|
||||||
|
# Sphinx documentation
|
||||||
|
docs/_build/
|
||||||
|
|
||||||
|
keys.*
|
||||||
|
# PyBuilder
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Jupyter Notebook
|
||||||
|
.ipynb_checkpoints
|
||||||
|
|
||||||
|
# IPython
|
||||||
|
profile_default/
|
||||||
|
ipython_config.py
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# pipenv
|
||||||
|
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
||||||
|
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
||||||
|
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
|
||||||
|
# install all needed dependencies.
|
||||||
|
#Pipfile.lock
|
||||||
|
|
||||||
|
# celery beat schedule file
|
||||||
|
celerybeat-schedule
|
||||||
|
|
||||||
|
# SageMath parsed files
|
||||||
|
*.sage.py
|
||||||
|
|
||||||
|
# Environments
|
||||||
|
.env
|
||||||
|
.venv
|
||||||
|
env/
|
||||||
|
venv/
|
||||||
|
ENV/
|
||||||
|
env.bak/
|
||||||
|
venv.bak/
|
||||||
|
|
||||||
|
# Spyder project settings
|
||||||
|
.spyderproject
|
||||||
|
.spyproject
|
||||||
|
|
||||||
|
# Rope project settings
|
||||||
|
.ropeproject
|
||||||
|
|
||||||
|
# mkdocs documentation
|
||||||
|
/site
|
||||||
|
|
||||||
|
# mypy
|
||||||
|
.mypy_cache/
|
||||||
|
.dmypy.json
|
||||||
|
dmypy.json
|
||||||
|
|
||||||
|
# Pyre type checker
|
||||||
|
.pyre/
|
||||||
|
|
||||||
|
# Azure Functions artifacts
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
appsettings.json
|
||||||
|
local.settings.json
|
||||||
|
.python_packages
|
6
.vscode/extensions.json
vendored
Normal file
6
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"recommendations": [
|
||||||
|
"ms-azuretools.vscode-azurefunctions",
|
||||||
|
"ms-python.python"
|
||||||
|
]
|
||||||
|
}
|
12
.vscode/launch.json
vendored
Normal file
12
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Attach to Python Functions",
|
||||||
|
"type": "python",
|
||||||
|
"request": "attach",
|
||||||
|
"port": 9091,
|
||||||
|
"preLaunchTask": "func: host start"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
7
.vscode/settings.json
vendored
Normal file
7
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"azureFunctions.deploySubpath": ".",
|
||||||
|
"azureFunctions.scmDoBuildDuringDeployment": true,
|
||||||
|
"azureFunctions.projectLanguage": "Python",
|
||||||
|
"azureFunctions.projectRuntime": "~3",
|
||||||
|
"debug.internalConsoleOptions": "neverOpen"
|
||||||
|
}
|
11
.vscode/tasks.json
vendored
Normal file
11
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "func",
|
||||||
|
"command": "host start",
|
||||||
|
"problemMatcher": "$func-watch",
|
||||||
|
"isBackground": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 2 Chainz REST API
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
8
host.json
Normal file
8
host.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0",
|
||||||
|
"extensionBundle": {
|
||||||
|
"id": "Microsoft.Azure.Functions.ExtensionBundle",
|
||||||
|
"version": "[1.*, 2.0.0)"
|
||||||
|
},
|
||||||
|
"extensions": { "http": { "routePrefix": "" } }
|
||||||
|
}
|
4
proxies.json
Normal file
4
proxies.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/proxies",
|
||||||
|
"proxies": {}
|
||||||
|
}
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
azure-functions
|
||||||
|
tweepy==3.8.0
|
||||||
|
requests==2.23.0
|
40
tweet/__init__.py
Normal file
40
tweet/__init__.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import datetime
|
||||||
|
import logging
|
||||||
|
import tweepy
|
||||||
|
from tweepy import TweepError
|
||||||
|
import azure.functions as func
|
||||||
|
import requests as r
|
||||||
|
from . import keys
|
||||||
|
|
||||||
|
|
||||||
|
def main(mytimer: func.TimerRequest) -> None:
|
||||||
|
# Authenticate to Twitter
|
||||||
|
auth = tweepy.OAuthHandler(keys.keys["API"], keys.keys["API_SECRET"])
|
||||||
|
auth.set_access_token(
|
||||||
|
keys.keys["TOKEN"], keys.keys["TOKEN_SECRET"],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create API object
|
||||||
|
api = tweepy.API(auth)
|
||||||
|
tweeted = False
|
||||||
|
tries = 0
|
||||||
|
while tweeted == False and tries < 10:
|
||||||
|
try:
|
||||||
|
quote = r.get("https://api.chainz.rest/quote").json()["quote"]
|
||||||
|
alias = r.get("https://api.chainz.rest/alias").json()["alias"]
|
||||||
|
|
||||||
|
api.update_status(status=f"{quote} - {alias}\n")
|
||||||
|
tweeted = True
|
||||||
|
tries += 10
|
||||||
|
except TweepError:
|
||||||
|
tries += 1
|
||||||
|
logging.warning(f"{quote} - {alias} - Has already been tweeted")
|
||||||
|
|
||||||
|
utc_timestamp = (
|
||||||
|
datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
|
||||||
|
)
|
||||||
|
|
||||||
|
if mytimer.past_due:
|
||||||
|
logging.info("The timer is past due!")
|
||||||
|
|
||||||
|
logging.info("Python timer trigger function ran at %s", utc_timestamp)
|
12
tweet/function.json
Normal file
12
tweet/function.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"scriptFile": "__init__.py",
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "mytimer",
|
||||||
|
"type": "timerTrigger",
|
||||||
|
"direction": "in",
|
||||||
|
"schedule": "0 0 10 * * MON",
|
||||||
|
"runOnStartup": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
10
tweet/readme.md
Normal file
10
tweet/readme.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
You need to add your twitter api keys to a `keys.py` file in this directory with the following format:
|
||||||
|
|
||||||
|
```python
|
||||||
|
keys = {
|
||||||
|
"API": "API_KEY_HERE",
|
||||||
|
"API_SECRET": "API_SECRET_KEY_HERE",
|
||||||
|
"TOKEN": "TOKEN_KEY_HERE",
|
||||||
|
"TOKEN_SECRET": "TOKEN_SECRET_KEY_HERE",
|
||||||
|
}
|
||||||
|
```
|
Reference in New Issue
Block a user