diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4890598 --- /dev/null +++ b/.gitignore @@ -0,0 +1,113 @@ +# 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/ +*.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/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# 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 + +.idea \ No newline at end of file diff --git a/lastfm2vkstatus.py b/lastfm2vkstatus.py new file mode 100644 index 0000000..9611100 --- /dev/null +++ b/lastfm2vkstatus.py @@ -0,0 +1,46 @@ +import pylast +import vk_api +import time +import sys +from settings import * + + +def main(): + + # Lastfm init + network = pylast.LastFMNetwork(api_key=API_KEY, api_secret=API_SECRET, + username=USERNAME, password_hash=pylast.md5(PASSWORD)) + + lastfm = pylast.User("", network) + + # VK init + vk_session = vk_api.VkApi(token=VK_USER_TOKEN) + vk = vk_session.get_api() + + last_track = '' + + while True: + if lastfm: + results = lastfm.get_now_playing() + if not results: + if last_track: + last_track = '' + vk.status.set(text="") + time.sleep(INTERVAL) + continue + if results != last_track: + time_now = time.strftime("%H:%M", time.localtime()) + status_text = f"🎧 Last.fm | {results}" + print(f"[{time_now}] {status_text}") + vk.status.set(text=status_text) + last_track = results + time.sleep(INTERVAL) + else: + time.sleep(INTERVAL) + else: + print(f"Can't get user") + sys.exit() + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..443a559 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pylast +vk_api \ No newline at end of file