def test_json_save(self): test_data = {"Hello": ["how", "are"], "You": "?", "I'm": True, "fine": 5} afile = reusables.join_paths(test_root, "test.json") try: reusables.save_json(test_data, afile) out_data = reusables.load_json(afile) finally: try: os.unlink(afile) except OSError: pass assert out_data == test_data
def openSettings(self): config = reusables.load_json('config.json') dlg = Setting_UI(self) dlg.path_line_edit.setText(config['path']) if dlg.exec_(): # If okay is pressed new_path = dlg.path_line_edit.text() if os.path.exists(new_path): self.PATH = new_path print(self.PATH) self.initUI() else: # If cancel is pressed pass
def __init__(self): super().__init__() self.old_disk_data = reusables.load_json('database.json') self.window_title = 'Movies' self.left = 300 self.top = 300 self.width = 920 self.height = 600 self.data = {} tmdb2imdb = {} # self.getConfig() self.movies = {} # Contains the id -> title of movies self.popular_movies = [] self.threaded_search = ThreadedSearcher() self.threaded_search.search_result.connect(self.search_response) self.initUI()
def test_json_save(self): test_data = { "Hello": ["how", "are"], "You": "?", "I'm": True, "fine": 5 } afile = reusables.join_paths(test_root, "test.json") try: reusables.save_json(test_data, afile) out_data = reusables.load_json(afile) finally: try: os.unlink(afile) except OSError: pass assert out_data == test_data
def getConfig(self): config = reusables.load_json('config.json') self.PATH = config['path']
def refresh_disk_data(self): disk_json = reusables.load_json('database.json') disk_json[self.movie_dat['id']] = self.movie_dat reusables.save_json(disk_json, 'database.json', indent=2)
import numpy as np import reusables ################################################################################################ ### More info about this recys recommender is in jupyter notebook file recys.ipynb ###### ################################################################################################ # Load up the files from tmdb_image import get_image_link similarities = np.loadtxt('data/similarities.csv', delimiter=',') movieId2idx = reusables.load_json('data/movieId2idx.json') movieId2title = reusables.load_json('./data/movieId2title.json') idx2movieId = reusables.load_json('./data/idx2movieId.json') movieId2TMDbid = reusables.load_json('./data/movieId2TMDbid.json') # Titles, This array is sent to front end as choices TITLES = sorted(list(movieId2title.items()), key=lambda x: x[1]) print(movieId2title) # Like titles are those titles that are liked by the user def get_recoms(liked_titles, no_of_recoms=10): liked_titles = [movieId2idx[str(i)] for i in liked_titles if str(i) in movieId2idx.keys()] number_of_titles = len(liked_titles) sim = similarities[liked_titles].sum(axis=0).argsort()[::-1][number_of_titles:no_of_recoms + number_of_titles] recoms = [ (movieId2title[str(idx2movieId[str(i)])], get_image_link(movieId2TMDbid[str(idx2movieId[str(i)])])) for i in sim] # generate recoms with poster image
import os import re from collections import defaultdict import marko import reusables from pathvalidate import sanitize_filename from slugify import slugify default_language = reusables.load_json('webserver_config.json')['default_language'] file_text = open('data.txt').read() # all_questions = reusables.load_json('data.json') all_questions = defaultdict(dict) def create_filesystem(topic_name, all_questions): if not os.path.exists('./Data/{}'.format(topic_name)): os.mkdir('./Data/{}'.format(topic_name)) if topic_name == 'Java': EXT = 'java' elif topic_name == 'Python': EXT = 'py' elif topic_name == 'CPP': EXT = 'cpp' else: EXT = default_language # Defautl lang is stored as extentions for question_name, question_value in all_questions[topic_name].items(): question_value['question_name'] = question_value['question_name'].strip('!')
from pathlib import Path, PosixPath from multiprocessing import Process import reusables from flask import Flask, render_template, redirect, request from jinja2 import environment from livereload import Server import create_filesystem app = Flask(__name__) app.jinja_env.filters['style'] = lambda u: style(u) data, topics = create_filesystem.get_data_for_html() topics = topics[::-1] webserver_config = reusables.load_json('webserver_config.json') editor_path = webserver_config['editor_path'] # APP = 'start "D:\\!t\\PyCharm 2020.2\\bin\\pycharm64.exe" "{}"' # APP = '"C:\\Users\\Nishan Paudel\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe" "{}"' # This will open in same window # APP = '"code" "{}"' # This will open in new VSCODE window APP = '"' + editor_path + '"' + ' "{}"' def style(field): if field.endswith("*"): # IMP, orange return 'color:orangered' elif field.endswith(':'): # Change in topic, dark green return 'color:darkolivegreen;text-decoration: underline;' return 'adfs'