def get_top_film(): url = 'https://api.douban.com/v2/movie/top250' for start in range(0, 250, 50): req = requests.get(url, params={'start': start, 'count': 50}) data = req.json() for movie in data['subjects']: print(movie) movie_str = json.dumps(movie) JsonUtil.write_file('1.json', movie_str) sleep(0.3)
def get_top_film(): '''https://douban.uieee.com/''' url = 'https://douban.uieee.com/v2/movie/top250' movie_list_str = '' for start in range(0, 250, 50): req = requests.get(url, params={'start': start, 'count': 50}) data = req.json() print(data) for movie in data['subjects']: print(movie) movie_str = json.dumps(movie) movie_list_str += movie_str + '\n' JsonUtil.write_file('src/main/resources/dataset/douban.json', movie_list_str) sleep(0.3)
def __onClickChangeDirButton(self, event): dialog = wx.DirDialog(None, defaultPath=self.__dirText.GetValue()) if dialog.ShowModal() == wx.ID_OK: defaultDir = dialog.GetPath() if os.name == "nt": # setting directory for Windows self.__dirText.SetValue(defaultDir + "\\" \ if not defaultDir.endswith("\\") else defaultDir) else: # for Linux or macOS self.__dirText.SetValue(defaultDir + "/" \ if not defaultDir.endswith("/") else defaultDir) conf = JsonUtil(CONFIGS).read() conf['dir'] = self.__dirText.GetValue() JsonUtil(CONFIGS).write(conf) dialog.Destroy()
def process_request(self, request_path, request, response): handle = self.handle_table.get(request_path) if handle: self.request = request self.response = response self.email = self.parse_email() ret = self.execute_handle(request_path, handle) if ret is None: return True msg = None if isinstance(ret, tuple): ret, msg = ret data = {} data['status'] = 'ok' if ret else 'error' if msg is not None: data['msg'] = msg print('ret = %s, data = %s' % (ret, data)) self.response.out.write(JsonUtil.encode(data)) return True print("can't find handle for %s" % request_path) return False
def test_json(self): return True, JsonUtil.decode(self.request.get('data'))
def __init__(self): wx.Frame.__init__(self, None, -1, title="YouTube Downloader", size=(FRAME_WIDTH, FRAME_HEIGHT), \ style=wx.DEFAULT_FRAME_STYLE) self.SetMinSize((FRAME_WIDTH, FRAME_HEIGHT)) self.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_CLOSE, self.__onClose) panel = wx.Panel(self) vBox = wx.BoxSizer(wx.VERTICAL) hBoxes = [] for i in range(5): # 5 boxsizer to place attributes properly hBoxes.append(wx.BoxSizer(wx.HORIZONTAL)) sourceLabel = wx.StaticText(panel, label="URLs:") self.__addButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/addButtonIcon.png")), style=wx.NO_BORDER) self.__addButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickAddButton, self.__addButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanAdd, self.__addButton) self.__playlistButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/playlistButtonIcon.png")), style=wx.NO_BORDER) self.__playlistButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickPlaylistButton, self.__playlistButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanAddPlaylist, self.__playlistButton) addBox = wx.BoxSizer(wx.HORIZONTAL) addBox.Add(self.__addButton, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=8) addBox.Add(self.__playlistButton, flag=wx.ALIGN_CENTER_VERTICAL) # labelGridSizer includes attributes that place on the top labelGridSizer = wx.GridSizer(cols=3) labelGridSizer.Add(sourceLabel, 0, wx.ALIGN_LEFT) labelGridSizer.Add(wx.StaticText(panel, size=(wx.GetDisplaySize().Width, -1)), 0, wx.EXPAND | wx.ALIGN_CENTER) labelGridSizer.Add(addBox, 0, wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) hBoxes[0].Add(labelGridSizer, flag=wx.EXPAND) vBox.Add(hBoxes[0], flag=wx.ALL, border=10) # text field to input urls self.__sourceText = wx.TextCtrl(panel, size=(-1, wx.GetDisplaySize().Height), style=wx.TE_MULTILINE) hBoxes[1].Add(self.__sourceText, proportion=1) vBox.Add(hBoxes[1], proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10) # a button to change download directory dirBox = wx.BoxSizer(wx.HORIZONTAL) self.__changeDirButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/changeDirButtonIcon.png")), style=wx.NO_BORDER) self.__changeDirButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickChangeDirButton, self.__changeDirButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanChangeDir, self.__changeDirButton) dirBox.Add(self.__changeDirButton, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=8) defaultDir = "" # set default download directory if os.path.exists(CONFIGS): # if the user has already set default directory, read it conf = JsonUtil(CONFIGS).read() defaultDir = conf['dir'] if not os.path.exists(defaultDir): # if saved default directory is corrupt, remove it and let user reset it os.remove(CONFIGS) os.execl(sys.executable, sys.executable, *sys.argv) # restart this program else: # otherwise, make the user set default directory dialog = wx.DirDialog(None) if dialog.ShowModal() == wx.ID_OK: defaultDir = dialog.GetPath() if os.name == "nt": # setting directory for Windows if not defaultDir.endswith("\\"): defaultDir += "\\" else: # for Linux or macOS if not defaultDir.endswith("/"): defaultDir += "/" conf = { 'dir': defaultDir } JsonUtil(CONFIGS).write(conf) else: # if the user click cancel, program should be exited self.Destroy() dialog.Destroy() # this text shows currently selected download directory self.__dirText = wx.TextCtrl(panel, value=defaultDir, size=(300, -1), style=wx.TE_READONLY) dirBox.Add(self.__dirText) # a meaningless icon optBox = wx.BoxSizer(wx.HORIZONTAL) prefIcon = wx.StaticBitmap(panel, -1, wx.Bitmap(resource_path("images/changePrefIcon.png"))) prefIcon.SetBackgroundColour(BACKGROUND_COLOR) optBox.Add(prefIcon, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=8) # a combobox which includes all available stream options that are available on selected video self.__prefCombobox = wx.ComboBox(panel, size=(200, -1), style=wx.CB_DROPDOWN | wx.TE_READONLY) self.Bind(wx.EVT_COMBOBOX, self.__onSelectOption, self.__prefCombobox) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanChangeOption, self.__prefCombobox) optBox.Add(self.__prefCombobox) # optionGridSizer includes attributes which place on the center optionGridSizer = wx.GridSizer(cols=3) optionGridSizer.Add(dirBox, 0, wx.ALIGN_LEFT) optionGridSizer.Add(wx.StaticText(panel, size=(wx.GetDisplaySize().Width, -1)), 0, wx.EXPAND | wx.ALIGN_CENTER) optionGridSizer.Add(optBox, 0, wx.ALIGN_RIGHT) hBoxes[2].Add(optionGridSizer, flag=wx.EXPAND) vBox.Add(hBoxes[2], flag=wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10) # a tabled list which includes download list self.__addedList = wx.ListCtrl(panel, style=wx.LC_REPORT | wx.BORDER_DOUBLE) cols = [ "제목", "저자", "길이", "옵션", "크기", "속도", "진행률", "남은 시간", "" ] # an empty column not to spoil UI when resizing columnWidths = [ 230, 80, 70, 180, 70, 85, 60, 70, wx.GetDisplaySize().Width ] for i in range(len(cols)): self.__addedList.InsertColumn(i, cols[i], wx.TEXT_ALIGNMENT_RIGHT if i == 0 else wx.TEXT_ALIGNMENT_CENTER) self.__addedList.SetColumnWidth(i, columnWidths[i]) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.__onSelectItem, self.__addedList) hBoxes[3].Add(self.__addedList, flag=wx.EXPAND | wx.LEFT | wx.RIGHT) vBox.Add(hBoxes[3], flag=wx.LEFT | wx.RIGHT, border=10) vBox.Add((-1, 10)) # add 6 buttons (start, pause, skip, stop, info, remove) self.__startButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/startButtonIcon.png")), style=wx.NO_BORDER) self.__startButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickStartButton, self.__startButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanStart, self.__startButton) hBoxes[4].Add(self.__startButton, flag=wx.RIGHT, border=12) self.__pauseButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/pauseButtonIcon.png")), style=wx.NO_BORDER) self.__pauseButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickPauseButton, self.__pauseButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanPause, self.__pauseButton) hBoxes[4].Add(self.__pauseButton, flag=wx.RIGHT, border=12) self.__skipButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/skipButtonIcon.png")), style=wx.NO_BORDER) self.__skipButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickSkipButton, self.__skipButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanSkip, self.__skipButton) hBoxes[4].Add(self.__skipButton, flag=wx.RIGHT, border=12) self.__stopButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/stopButtonIcon.png")), style=wx.NO_BORDER) self.__stopButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickStopButton, self.__stopButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanStop, self.__stopButton) hBoxes[4].Add(self.__stopButton, flag=wx.RIGHT, border=12) self.__infoButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/infoButtonIcon.png")), style=wx.NO_BORDER) self.__infoButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickInfoButton, self.__infoButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanShowInfo, self.__infoButton) hBoxes[4].Add(self.__infoButton, flag=wx.RIGHT, border=12) self.__removeButton = wx.BitmapButton(panel, -1, wx.Bitmap(resource_path("images/removeButtonIcon.png")), style=wx.NO_BORDER) self.__removeButton.SetBackgroundColour(BACKGROUND_COLOR) self.Bind(wx.EVT_BUTTON, self.__onClickRemoveButton, self.__removeButton) self.Bind(wx.EVT_UPDATE_UI, self.__onCheckCanRemove, self.__removeButton) hBoxes[4].Add(self.__removeButton) vBox.Add(hBoxes[4], flag=wx.ALIGN_RIGHT | wx.RIGHT, border=10) vBox.Add((-1, 10)) panel.SetSizer(vBox) # status bar to show events self.CreateStatusBar() self.GetStatusBar().SetBackgroundColour(BACKGROUND_COLOR) self.SetStatusText("") self.__downloadList = [] self.__downloading = False self.__plm = PlaylistManager() self.__am = None # AddManager for adding urls self.__dm = None # DownloadManager for downloading videos self._lock = threading.Lock() self.Center() self.Show() PlaylistDialog(self, self.__plm).autoAddPlaylist()
def delete_tables(): jmapper = JMAPPER() jmapper.drop_table() json_util = JsonUtil() json_util.drop_table()
from jmapper import JMAPPER from json_util import JsonUtil jmapper = JMAPPER() json_util = JsonUtil() def build_schema(): create_tables() create_indices() jmapper.preprocessing() json_util.preprocessing() def create_tables(): jmapper.create_lookup_table() jmapper.create_string_table() json_util.create_json_table() def create_indices(): jmapper.create_index() json_util.create_index() def delete_tables(): jmapper = JMAPPER() jmapper.drop_table() json_util = JsonUtil() json_util.drop_table()
def get_json(cls, url, value_map): """ Send value_map to the url, and receive json reply. """ reply = cls.get(url, value_map) #print('reply = ', reply) return JsonUtil.decode(reply)