Esempio n. 1
0
    def __init__(self):
        super().__init__('s')

        self.add_rule(self.create)
        self.add_rule(self.addQuestion)
        self.add_rule(self.getQuestions)
        self.add_rule(self.publish)
        self.add_rule(self.like)
        self.add_rule(self.getCurrentSurveyId)
        self.add_rule(self.setInfo)
        self.add_rule(self.getInfo)
        self.add_rule(self.setAnswer)
        self.add_rule(self.getAnswer)
        self.add_rule(self.getInfos, methods=['POST', 'GET'])
        self.add_rule(self.getImage, methods=['POST', 'GET'])

        self.app_config = config
        db_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_NAME'])
        tables_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_TABLES'])

        self.db = Database(db_path)
        self.db.execute_file(tables_path)

        self.request = Request()
        self.response = Response()
        self.security = Security()
        self.filesender = FileSender()
        self.requester = Requester(self.db)

        self.form_checker = FormChecker()
        self.error = Error()
Esempio n. 2
0
 def run(self):
     # 输入搜索结果,输出所需要的搜索内容_url
     search_html = Request(self.url+'/search?q='+self.value, 'search url').request()
     dest_urls = Parse(search_html).parse_search_html()
     
     # 存储所有目标字幕的下载页
     download_urls = []
     for dest_url in dest_urls:
         # 获取每一个字幕文件的主页url
         detail_html = Request(self.url + dest_url, 'detail url').request()
         sub_urls = Parse(detail_html).parse_detail()
         for sub_url in sub_urls:
             # 获取字幕文件下载页的url
             sub_html = Request(self.url + sub_url, 'sub url').request()
             download_page_url = Parse(sub_html).parse_sub_url()
             click_download = Downloader(self.url + download_page_url).download()
Esempio n. 3
0
def main():

    search = input('请输入您想搜索的美剧,注意声明全名和季数哦: ')

    url = 'https://www.ttkmj.net'
    main_url = Search(url, search).search()
    print(main_url)
    dest_html = Request(main_url, 'search result').request()
    dest_url = Destination(dest_html).parse_result()
    print(dest_url)
    links_html = Request(dest_url, 'target page').request()
    links = Links(links_html).parse_links()
    print(links)
    # 最后写入到目标文件夹中完成保存,学会读写文本:文件夹+操作方式
    f = open('./source/{}.html'.format(search), 'w')
    for link in links:
        f.write(link)
        f.write('\n')
    f.close()
Esempio n. 4
0
    def __init__(self):

        db_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_NAME'])
        tables_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_TABLES'])

        self.db = Database(db_path)
        self.db.execute_file(tables_path)

        self.request = Request()
        self.response = Response()
        self.security = Security()
    def __init__(self):
        super().__init__()

        self.add_rule(self.main_page, url='/nt', methods=['GET'])
        self.add_rule(self.favicon, url='/favicon.ico', methods=['GET'])
        self.add_rule(self.style, methods=['GET', 'POST'])
        self.add_rule(self.script, methods=['GET', 'POST'])
        self.add_rule(self.svg, methods=['GET', 'POST'])
        self.add_rule(self.photo, methods=['GET', 'POST'])

        self.add_rule(self.templates)
        self.add_rule(self.svgs)

        self.app_config = config

        self.response = Response()
        self.security = Security()
        self.filesender = FileSender()
        self.request = Request()
Esempio n. 6
0
class Surveys(Module):
    def __init__(self):
        super().__init__('s')

        self.add_rule(self.create)

        self.app_config = config

		db_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_NAME'])
		tables_path = os.path.join(config['DATABASE_PATH'], config['DATABASE_TABLES'])

		self.db = Database(db_path)
		self.db.execute_file(tables_path)

        self.security = Security()
        self.filesender = FileSender()
        self.request = Request()
        self.requester = Requester(db)

        self.form_checker = FormChecker()
Esempio n. 7
0
    def run(self):
        self.print_movie_list()
        self.indexstr = input('请输入您需要的电影序号,多个请用空格隔开:')
        self.parse_index()
        self.delete_file()

        for index in self.index_list:
            self.movie_url = Search(
                url_index=index, search_html=self.search_html).get_index_url()
            self.movie_html = Request(self.movie_url, 'movie url').request()

            self.movie_content = Parse(movie_html=self.movie_html)
            self.links = self.movie_content.parse_movie_links()
            self.img = self.movie_content.get_img_url()
            self.movie_name = self.movie_content.get_movie_name()

            self.html = Html(file_name=self.value,
                             links=self.links,
                             img_link=self.img,
                             movie_name=self.movie_name,
                             split=True)
            self.html.write_to_html()
Esempio n. 8
0
    def handle(self, sock):
        bytes = b''
        while not bytes.endswith(b'\n'):
            bytes += sock.recv(1024)

        data = bytes.decode()
        request = Request(data)

        if request.method not in const.ALLOWED_METHODS:
            sock.sendall(ResponseNotAllowed().encode())
            return

        if not request.is_ok:
            sock.sendall(ResponseBadResponse().encode())
            return

        if '/../' in request.path:
            sock.sendall(ResponseForbidden().encode())
            return

        request.path = unquote(request.path.split('?')[0])

        request.path = os.getcwd() + request.path
        if os.path.isdir(request.path):
            request.path += 'index.html'
            if not os.path.isfile(request.path):
                sock.sendall(ResponseForbidden().encode())

        try:
            body = self.read_file(request.path)
        except Exception:
            sock.sendall(ResponseNotFound().encode())
            return

        response = ResponseOK(body, request.path, request.method)
        sock.sendall(response.encode())
Esempio n. 9
0
import os
import sys

from tools.config import Config
from tools.request import Request

if __name__ == '__main__':
    status = sys.stdin.read()
    filename = sys.argv[1] if len(sys.argv) == 2 else 'config.json'
    path = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
    config = Config(path)
    request = Request(config)
    result = request.post('statuses', {'status': status})
    if 'error' in result[1]:
        print('an error "{}" occurred while posting a toot.'.format(
            result[1]['error']),
              file=sys.stderr)
        exit(1)
    else:
        print(result[1]['url'])