1
0
Fork 0
mirror of https://github.com/fastogt/fastocloud_admin.git synced 2025-03-09 23:38:52 +00:00

Init sources

This commit is contained in:
topilski 2020-02-08 22:27:17 -05:00
commit 92648275c3
156 changed files with 18906 additions and 0 deletions

View file

View file

@ -0,0 +1,22 @@
from app.home.entry import ProviderUser
from app.service.service import ServiceSettings, ProviderPair
def import_resellers_to_server(db, server: ServiceSettings):
cursor = db.cursor(dictionary=True)
sql = 'SELECT username,email,password from reg_users'
cursor.execute(sql)
sql_providers = cursor.fetchall()
for sql_entry in sql_providers:
email = sql_entry['email']
password = sql_entry['email']
new_user = ProviderUser.make_provider(email=email, password=password, country='US', language='en')
new_user.status = ProviderUser.Status.ACTIVE
new_user.save()
admin = ProviderPair(new_user.id, ProviderPair.Roles.ADMIN)
server.add_provider(admin)
new_user.add_server(server)
cursor.close()

View file

@ -0,0 +1,35 @@
import json
from pyfastocloud_models.stream.entry import ProxyStream
from app.service.service import ServiceSettings
from pyfastocloud_models.utils.utils import is_valid_http_url
import pyfastocloud_models.constants as constants
def import_streams_to_server(db, server: ServiceSettings):
cursor = db.cursor(dictionary=True)
sql = 'SELECT stream_source, stream_display_name, stream_icon, channel_id from streams'
cursor.execute(sql)
sql_streams = cursor.fetchall()
for sql_entry in sql_streams:
stream = ProxyStream.make_stream(server)
urls = json.loads(sql_entry['stream_source'])
if not len(urls):
continue
stream.output.urls[0].uri = urls[0]
stream.name = sql_entry['stream_display_name']
tvg_logo = sql_entry['stream_icon']
if len(tvg_logo) < constants.MAX_URL_LENGTH:
if is_valid_http_url(tvg_logo, timeout=0.1):
stream.tvg_logo = tvg_logo
epg_id = sql_entry['channel_id']
if epg_id:
stream.tvg_id = epg_id
stream.save()
server.streams.append(stream)
server.save()
cursor.close()

View file

@ -0,0 +1,31 @@
from datetime import datetime
from pyfastocloud_models.subscriber.entry import Subscriber
from pyfastocloud_models.subscriber.entry import Device
from app.service.service import ServiceSettings
def import_subscribers_to_server(db, server: ServiceSettings):
cursor = db.cursor(dictionary=True)
sql = 'SELECT username,password,created_at,exp_date FROM users'
cursor.execute(sql)
sql_subscribers = cursor.fetchall()
for sql_entry in sql_subscribers:
new_user = Subscriber.make_subscriber(email=sql_entry['username'], first_name=sql_entry['username'],
last_name=sql_entry['username'], password=sql_entry['password'],
country='US', language='US')
new_user.status = Subscriber.Status.ACTIVE
created_at = sql_entry['created_at']
if created_at:
new_user.created_date = datetime.fromtimestamp(created_at)
exp_date = sql_entry['exp_date']
if exp_date:
new_user.exp_date = datetime.fromtimestamp(exp_date)
dev = Device(name='Xtream')
new_user.add_device(dev)
# save
new_user.add_server(server)
server.add_subscriber(new_user)
cursor.close()