def add_saved_station(self, widget): id = self.musicPlayer.get_playing_station_id() if id != 0: if Config().is_station_saved(id): Config().remove_station(id) else: StationRequester(self).request_by_id(id)
def __init__(self, host, port): Config.__init__(self) Log.__init__(self, self._env['SERVER_LOG']) self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__connections = [] self.__host = host self.__port = port
def __init__(self, window=None): Config.__init__(self) Log.__init__(self) self._controller_path = 'controller' self._model_path = 'model' self._view_path = 'view' self._window = window self._current_view = None
def get_local_thumbnail(self, stationId, width, height): pixbuf = None try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(Config().get_cache_folder(), stationId), width, height) except: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('../ui/icon_512_2.png', width, height) return pixbuf
def fill_saved_station_list(self, widget): #self.newSearchStationsListStore.clear() self.savedStationsListStore.clear() content = Config().get_saved_stations() for station in content: data = json.loads(str(station).replace("\'", "\"").replace("\\", "\\\\")) try: self.savedStationsListStore.append([self.get_thumbnail(data['id']), data['name'].replace('\\xa0', ' '), data['id'], data['url'], data['homepage'], data['favicon'], data['country'], data['tags'], data['votes'], data['codec']]) except: print("could not add station " + data['id']) for icon in self.savedStationsListStore: StationThumbnailDownloader(self, icon[2], False).go(icon[5]) self.iconViewSpinner.stop()
def fill_search_results(self, data): self.newSearchStationsListStore.clear() for station in data: name = station['name'] url = station['url'] favicon = station['favicon'] id = station['id'] web = station['homepage'] country = station['country'] tags = station['tags'] votes = station['votes'] codec = station['codec'] width = 92 #should be set in settings height = 92 #should be set in settings if ".pls" not in url and station['lastcheckok'] != "0": #exclude .pls and broken stations try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(Config().get_cache_folder(), id), width, height) except: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('../ui/icon_512_2.png', width, height) StationThumbnailDownloader(self, id, True).go(favicon) try: self.newSearchStationsListStore.append([pixbuf, name, id, url, web, favicon, country, tags, votes, codec]) except: print("den virkede ikke") self.iconViewSpinner.stop()
def get_thumbnail(self, sid): width = 92 #should be set in settings height = 92 #should be set in settings try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(Config().get_cache_folder(), sid), width, height) except: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('../ui/icon_512_2.png', width, height) return pixbuf
def check_exclude(path): config = Config() exclude_dir = config.get_config('exclude', 'dir', '') is_exclude = False if exclude_dir != '': exclude_dir = exclude_dir.split(',') for dir_name in exclude_dir: try: if path.index(dir_name) > -1: is_exclude = True except ValueError: continue exclude_file = config.get_config('exclude', 'file', '') if exclude_file != '': exclude_file = exclude_file.split(',') for file_name in exclude_file: try: if path.index(file_name) > -1: is_exclude = True except ValueError: continue return is_exclude
def changeThumbnail(self, stationId, newSearch): try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(Config().get_cache_folder(), stationId), 92, 92) if newSearch: listStore = self.newSearchStationsListStore else: listStore = self.savedStationsListStore for station in listStore: if station[2] == stationId: station[0] = pixbuf except: pass
def save_new_station(self, data): if len(data) > 0: station = data[0] name = station['name'] url = station['url'] favicon = station['favicon'] sid = station['id'] web = station['homepage'] country = station['country'] tags = station['tags'] votes = station['votes'] codec = station['codec'] Config().add_saved_station(sid, name, url, web, country, favicon, tags, votes, codec) self.check_if_saved(None) self.fill_saved_station_list(None)
def on_ready_callback(self, source_object, result, user_data): try: success, content, etag = source_object.load_contents_finish(result) outputfile = open( os.path.join(Config().get_cache_folder(), self.stationId), "wb") outputfile.write(content) self.view.changeThumbnail(self.stationId, self.newSearch) except GLib.GError as e: pass #print("Error: " + self.stationId + " " + e.message) #else: #content_text = content[:100].decode("utf-8") #self.append_text("Got content: " + content_text + "...") finally: self.cancellable.reset()
def selectStation(self, liststore, index): pixbuf = None try: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.join(Config().get_cache_folder(), liststore[index][2]), 64, 64) self.imgStationDetailsImage.set_from_pixbuf(pixbuf) except: pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size('../ui/icon_512_2.png', 64, 64) self.activeStationPlayBarThumbnail.set_from_pixbuf(pixbuf) self.lblSongName.set_label("") self.songNameLoadingSpinner.start() self.fill_detailswindow(liststore[index]) self.musicPlayer.play(liststore[index][3], liststore[index][2]) self.set_current_station_name(liststore[index][1]) self.check_if_saved(None)
def __init__(self, application_id, flags): Gtk.Application.__init__(self, application_id=application_id, flags=flags) Config().startup() self.connect("activate", self.new_window)
class Sftp(object): def __init__(self, remote_path): self.config = Config() self.sftp = self.connection() self.remote_path = remote_path def connection(self): print('start connection sftp............') sftp_host = self.config.get_config('sftp', 'host', '') sftp_port = self.config.get_config('sftp', 'port', '') sftp_user_name = self.config.get_config('sftp', 'userName', '') sftp_public_key = self.config.get_config('sftp', 'publicKey', '') sftp_user_password = self.config.get_config('sftp', 'password', None) if sftp_host == '' or sftp_port == '' or sftp_user_name == '': print('sftp config error..............') time.sleep(5) exit() ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: if sftp_public_key != '': if sftp_user_password is None: key = paramiko.RSAKey.from_private_key_file( sftp_public_key) else: key = paramiko.RSAKey.from_private_key_file( sftp_public_key, sftp_user_password) ssh.connect(sftp_host, sftp_port, sftp_user_name, sftp_user_password, key) else: if sftp_user_password is None: print('password is none...............') time.sleep(5) exit() ssh.connect(sftp_host, sftp_port, sftp_user_name, sftp_user_password) except paramiko.ssh_exception.AuthenticationException: print('sftp connection error..................') time.sleep(5) exit() except NoValidConnectionsError: print('sftp connection error..................') time.sleep(5) exit() print('sftp connection success..................') transport = ssh.get_transport() sftp = paramiko.SFTPClient.from_transport(transport) return sftp def check_remote_path(self): try: self.sftp.stat(self.remote_path) except IOError: print('remote dir is undefined,create new dir') self.sftp.mkdir(self.remote_path) def check_dir(self, folder): try: self.sftp.stat(folder) except IOError: print('remote dir is undefined,create new dir:' + folder) except SSHException: print('sftp connection dropped........') print('connection sftp server again.........') self.sftp = self.connection() self.check_dir(folder) def upload(self, local_path, upload_path): try: local_file = local_path remote_file = self.remote_path + upload_path remote_dir = os.path.dirname(remote_file) self.check_dir(remote_dir) print('upload to file:' + remote_file) self.sftp.put(local_file, remote_file) print('upload success') except WindowsError: print('sftp upload error') except SSHException: print('sftp connection dropped........') print('connection sftp server again.........') self.sftp = self.connection() self.upload(local_path, upload_path) except IOError: print('sftp upload error') def create_dir(self, dir_name): remote_dir = self.remote_path + dir_name try: self.sftp.stat(remote_dir) print('dir exist') except IOError as error: print('IO ERROR........' + error.message) except SSHException: print('sftp connection dropped........') print('connection sftp server again.........') self.sftp = self.connection()
def check_if_saved(self, widget): stationId = self.musicPlayer.get_playing_station_id() if Config().is_station_saved(stationId): self.imgSavedStationIcon.set_from_icon_name("gtk-apply", 1) else: self.imgSavedStationIcon.set_from_icon_name("list-add", 1)
def __init__(self, remote_path): self.config = Config() self.sftp = self.connection() self.remote_path = remote_path
import os import firebase_admin import flask from flask_cors import CORS from flask import request, abort, jsonify, make_response from helpers.helpers import google_search_crawlera, get_first_result, get_bool from helpers.Config import Config app = flask.Flask(__name__) CORS(app) firebase_admin.initialize_app() config = Config(os.getenv('FLASK_ENV') or 'prod') @app.route('/api/search', methods=['POST']) def google_search(): # get the google search first result request_json = None try: request_json = request.json except: abort(make_response(jsonify(message='Body is required.'), 400)) query = request_json.get('query', None) if query is None: abort( make_response( jsonify(message='Input must contains query parameter.'), 409)) search_engine = request_json.get('search_engine', 'com.au')
# -- coding: utf-8 -- from helpers.Config import Config from helpers.Sftp import Sftp from helpers.Watchdog import Watchdog import time if __name__ == "__main__": config = Config() # 获取要监控的目录 local_path = config.get_config('document', 'localPath', '') print('watch dir:' + local_path + '...................') # 获取sftp配置 remote_path = config.get_config('document', 'remotePath', '') if local_path == '' or remote_path == '': print('path error..................') time.sleep(5) exit() # sftp链接 sftp = Sftp(remote_path) sftp.check_remote_path() # watchdog监控文件 dog = Watchdog(local_path, sftp) dog.start()
def go(self, url): file_ = Gio.File.new_for_uri(url) file_.load_contents_async(self.cancellable, self.on_ready_callback, Config().get_cache_folder())
try: if isinstance(obj, date): return obj.strftime('%Y-%m-%d %H:%M:%S') iterable = iter(obj) except TypeError: pass else: return list(iterable) return JSONEncoder.default(self, obj) app = Flask(__name__, static_folder='static') app.json_encoder = CustomJSONEncoder # get Config config = Config("../config/config.yaml").get() # Connect to DB try: db = mysql.connect(host=config['database']['host'], port=config['database']['port'], user=config['database']['user'], passwd=config['database']['password'], database=config['database']['database']) cursor = db.cursor(dictionary=True) except (mysql_errors.ProgrammingError, mysql_errors.InterfaceError) as exc: if config['general']['debug']: msg = 'Cannot connect to database. Got error: {}'.format(exc) else: msg = 'Cannot connect to database.'
def __init__(self, controller): Config.__init__(self) Log.__init__(self, self._env['CLIENT_LOG']) self.__sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.__controller = controller