示例#1
0
def get_js(js, js_fun, js_params):
    try:
        import execjs  # pip install PyExecJS
    except:
        raise LibraryNotInstallError('安装:pip install PyExecJS')
    ctx = execjs.compile(js)  # 加载JS文件
    return ctx.call(js_fun, *js_params)  # 调用js方法  第一个参数是JS的方法名,后面的data和key是js方法的参数
示例#2
0
def analysis(data_name, response_headers=Response_Headers):
    """分析单词、爬去小D网站:https://dict.hjenglish.com/jp/jc/%E3%81%AB%E3%81%8E%E3%82%8F%E3%81%86"""
    try:
        from bs4 import BeautifulSoup  # pip install bs4
    except Exception as _:
        raise LibraryNotInstallError('安装 pip install bs4')
    total = []
    ws = open(data_name + '.data', 'w', encoding='utf8')
    with open(data_name, encoding='utf8') as f:
        for line in f:
            lines = line[:-1]
            if len(lines) > 1 and (lines not in total):
                total.append(lines)
                name = lines
                url = F'https://dict.hjenglish.com/jp/jc/{quote(name)}'
                response = requests.get(
                    url=url, headers=jtyoui.header(response_headers))
                data = response.text
                sp = BeautifulSoup(data, 'html.parser')
                pjm = sp.find(class_='pronounces')
                if pjm:
                    pjm = pjm.span.text[1:-1]
                else:
                    continue
                cx = sp.find(class_='simple')
                x = cx.h2
                if x:
                    x = x.text[1:-1]
                else:
                    continue
                m = cx.ul.text.replace('\n', '')
                m = sub_names(m).replace('。', ';')[:-1]
                if len(m) > 40:
                    continue
                if name != pjm:
                    name = "(" + name + ")"
                else:
                    name = None
                x = '<' + x + '>'
                for k, v in word.items():
                    x = x.replace(k, v)
                x = x.replace('词', '')
                if len(m) <= 1:
                    continue
                if name:
                    string = F'{pjm}{name}\t{x}\t{m}'
                else:
                    string = F'{pjm}\t{x}\t{m}'
                print(string)
                ws.write(string + '\n')
                ws.flush()
示例#3
0
def cut(text_name):
    """从原始数据里面提取日语单词
    :param text_name:原始数据的文件地址
    :return:返回提取数据文本的地址
    """
    try:
        from janome.tokenizer import Tokenizer  # pip install janome
    except Exception as _:
        raise LibraryNotInstallError('安装 pip install janome')

    w = open(text_name + '.jp', 'w', encoding='utf8')
    t = Tokenizer()
    fp = open(text_name, encoding='utf-8')
    for token in t.tokenize(fp.read()):
        words = token.base_form
        words = words.replace(' ', '')
        if len(words) > 1:
            w.write(words + '\n')
    return text_name + '.jp'
示例#4
0
文件: image.py 项目: zerowq/Jtyoui
# @Email  : [email protected]
# @Software: PyCharm
from jtyoui.error import LibraryNotInstallError
from jtyoui.tools import pips
import os
import glob
import zipfile
import shutil

try:
    import fitz  # 安装 pip install PyMuPDF
except ModuleNotFoundError:
    try:
        fitz = pips('fitz', 'PyMuPDF')  # 自动安装
    except ModuleNotFoundError:
        raise LibraryNotInstallError("安装 pip install PyMuPDF")


def _get_dir_name(file_dir):
    base_name = os.path.basename(file_dir)  # 获得地址的文件名
    dir_name = os.path.dirname(file_dir)  # 获得地址的父链接
    return dir_name, base_name


def image_pdf(file_dir, pdf_address=None):
    """
    照片转pdf
    :param file_dir: 照片的地址文件夹
    :param pdf_address: 保存pdf的文件地址,默认是当前地址
    :return: 成功返回True
    """
示例#5
0
#!/usr/bin/python3.7
# -*- coding: utf-8 -*-
# @Time : 2019/2/14 0014
# @Email : [email protected]
import requests
from jtyoui.web import random
from jtyoui.error import LibraryNotInstallError
import re

try:
    import itchat  # 安装 pip install itchat
except ModuleNotFoundError:
    raise LibraryNotInstallError("安装 pip install itchat")

url = 'https://m.xunleige.com/'


def movie(name):
    param = dict(searchword=name.encode('gb2312'))
    response = requests.post(url + 'search.asp',
                             data=param,
                             headers={'User-Agent': random()})
    response.encoding = 'GBK'
    data = response.text
    find, = re.findall(pattern=r'<div class="list mb">(.+)</div>',
                       string=data,
                       flags=re.S)
    message = re.findall(pattern='a href="(.+)" title="(.+)" class',
                         string=find)
    return message
示例#6
0
# -*- coding: utf-8 -*-
# @Time    : 2018/1/2 16:30
# @Email  : [email protected]
# @Software: PyCharm

import random
import sys
import time
from jtyoui.error import LibraryNotInstallError
from urllib.request import urlretrieve
import os

try:
    import pygame
except ModuleNotFoundError:
    raise LibraryNotInstallError("安装pygame包: pip install pygame")

SCREEN_WIDTH, SCREEN_HEIGHT = 1200, 700
MY_BIRTH_LEFT, MY_BIRTH_TOP = SCREEN_WIDTH / 2, SCREEN_HEIGHT - 60
DIRECTION = [U, D, L, R] = ['U', 'D', 'L', 'R']
Tank_IMAGE_POSITION = './tank_img'
URL = 'https://gitee.com/tyoui/logo/raw/master/img/'


def load_img(name_img):
    save = Tank_IMAGE_POSITION + os.sep + name_img + '.gif'
    if not os.path.exists(save):
        urlretrieve(URL + name_img + '.gif', save)
    return pygame.image.load(save)