Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchTaqi committed Jul 22, 2017
1 parent c342e44 commit 325ed49
Show file tree
Hide file tree
Showing 10 changed files with 210 additions and 85 deletions.
86 changes: 1 addition & 85 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,96 +6,12 @@ __pycache__/
# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# 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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.idea
64 changes: 64 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn src/main:app --log-file=-
22 changes: 22 additions & 0 deletions src/ transferdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
import dropbox

class TransferData:
def __init__(self, access_token):
self.access_token = access_token

def upload_file(self, file_from=None, file_to=None):
"""upload a file to Dropbox using API v2
"""
dbx = dropbox.Dropbox(self.access_token)

with open(file_from, 'rb') as f:
dbx.files_upload(f.read(), file_to)

#----------------------------------------------------------------------
def get_account_info(self):
"""
Returns the account information, such as user's display name,
quota, email address, etc
"""
return self.client.account_info()
Empty file added src/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from radiorec import record_radio
from transferdata import TransferData


def main():
radio_record = record_radio('http://audio.samaafm.com:8008/1')
file_name = radio_record.record_radio()
drop_box_access_token = os.environ.get('access_token')
target_dir = os.environ.get('target_dir')
upload_to = target_dir + os.sep + file_name
transfer_data = TransferData(drop_box_access_token)
transfer_data.get_account_info()
transfer_data.upload_file(file_name, upload_to)

if __name__ == '__main__':
main()
59 changes: 59 additions & 0 deletions src/radiorec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
"""
radiorec.py – Recording internet radio streams and Upload to SoundCloud
Copyright (C) 2017 Muhammad Taqi <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

# import libraries
import datetime
import urllib.request


class record_radio:

def __init__(self, stream_url):
self.stream_url = stream_url

def __enter__(self):
print('__enter__')

def __exit__(self, typ, value, tb):
print('__exit__')

def init(self):
print("init")

def start(self):
print("start")

def stop(self):
print("stop")

def finish(self):
print("finish")

def record_radio(self):
d = datetime.date.today()
filename = "recording" + d.strftime("%Y%m%d")+".ogg"
stream = urllib.request.urlopen(self.stream_url)
start_time = datetime.datetime.now()
dest = open(filename, 'wb')
while (datetime.datetime.now() - start_time).seconds <= 30:
print((datetime.datetime.now() - start_time).seconds)
dest.write(stream.read(1024))
return filename



33 changes: 33 additions & 0 deletions src/transferdata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import dropbox


class TransferData:

def __init__(self, access_token):
self.access_token = access_token

def upload_file(self, file_from=None, file_to=None):
"""
upload a file to Dropbox using API v2
:param file_from:
:param file_to:
:return:
"""
client = dropbox.Dropbox(self.access_token)
try:
with open(file_from, 'rb') as f:
meta = client.files_upload(f.read(), file_to, mute=True)
print("Uploaded " + file_to)
except:
print("Failed to upload " + file_to)

def get_account_info(self):
"""
Returns the account information, such as user's display name, quota,
email address, etc
:return:
"""
client = dropbox.Dropbox(self.access_token)
print(client.users_get_current_account())

0 comments on commit 325ed49

Please sign in to comment.