定时爬虫抓当日免费应用:Scrapy + Tkinter + LaunchControl

news/2024/7/19 9:40:41 标签: 爬虫, python, json

花了个周末学了下Scrapy,正好一直想买mindnode,于是顺手做了个爬虫,抓取爱范儿每天的限免应用信息。

Thinking

大概思路就是使用LaunchControl每天定时(比如早上9点50,这时正好刚到公司不久)跑一下爬虫脚本,如果找到感兴趣的应用在限免,就使用Tkinter弹出提示。当然,也可以直接用Scrapy做定时任务,以后再说。

Coding

Scrapy + Tkinter

# -*- coding: utf-8 -*-
import scrapy
import Tkinter
from scrapy.shell import inspect_response
import json

# 设置感兴趣的app名称
I_want_apps = set(['mindnode pro', 'u.memory'])

class XianmianSpider(scrapy.Spider):
    user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36'
    name = "xianmian"
    allowed_domains = ["app.so"]
    start_urls = (
        'http://app.so/api/v1.1/appso/discount/?platform=web&limit=10',
    )

    def parse(self, response):

        jsonresponse = json.loads(response.body_as_unicode())

        apps = jsonresponse['objects']

        appTitles = {item['display_name'].lower() for item in apps}

        self.logger.info('today\' apps are: ' + str(appTitles))

        the_apps = appTitles & I_want_apps
        if the_apps:
            self.showMsg('found the apps: {}'.format(list(the_apps)))

    def showMsg(self, msg):
        import Tkinter
        root = Tkinter.Tk()
        root.title('福利到!')
        label = Tkinter.Label(root, text=msg)
        label.pack()
        center_window(root, 300, 240)
        root.maxsize(600, 400)
        root.minsize(300, 240)
        Tkinter.mainloop()
def get_screen_size(window):  
    return window.winfo_screenwidth(),window.winfo_screenheight()  
  
def get_window_size(window):  
    return window.winfo_reqwidth(),window.winfo_reqheight()  
  
def center_window(root, width, height):  
    screenwidth = root.winfo_screenwidth()  
    screenheight = root.winfo_screenheight()  
    size = '%dx%d+%d+%d' % (width, height, (screenwidth - width)/2, (screenheight - height)/2)  
    print(size)  
    root.geometry(size)  

LaunchControl

LaunchControl用起来比较直观。当然,也可以直接用mac自带的launchctl,具体可参考launchctl使用说明


http://www.niftyadmin.cn/n/1593052.html

相关文章

centos php-config,Centos 安装 PHP 5.4.3 报 configure error xml2-config

参考:http://www.jsjtt.com/xitongyingyong/linux/17.htmlCentos 安装 PHP 5.4.3 报 configure error xml2-config not found. please check your libxml2 installation 错误检查是否安装了libxm包[rootrh-linux software]# rpm -qa |grep libxml2libxml2-2.6.26-2…

Win7 配置Apache+PHP+Mysql环境

2019独角兽企业重金招聘Python工程师标准>>> 第一、安装并配置APACHE(安装到D:\phpapache\Apache2.2) 1、安装时默认安装,Network Domain, Server Name 我填写我的计算机名,Administrators Email Address区域填你…

Swift字符串的插入、删除和替换-备

对应可变字符串可以插入、删除和替换,String提供了几个方法可以帮助实现这些操作。这些方法如下: splice(_:atIndex:)。在索引位置插入字符串。 insert(_:atIndex:)。在索引位置插入字符。 removeAtIndex(_:)。在索引位置删除字符。 removeRange(_:)。删…

php 两个箭头,电脑图标右上角有两个箭头怎么办?

电脑图标出现双箭头的解决方法:首先选择图标右键,依次选择“属性-->高级”;然后在“压缩或加密属性”中取消勾选“压缩内容以便节省磁盘空间”和“加密内容以便保护数据”两个选项;最后返回“文件属性”对话框,点“…

前端开发的级别及要求

前端开发初级1.掌握html、css、javascript基础知识,会使用业内框架例如jQuery,熟练调用框架提供的常用API和组件,能够完成ajax数据通信2.分析视觉稿,使用Phototshop等设计工具产出图片等素材文件,最终能够产出具备良好…

discuz 模板php,Discuz 模板语句分析及知识技巧

一、模板调用比如在某个模板中,想调用另一个模板中的内容,可以用下面的语句:{template xxx}假设,建立了一个新模板名字叫 "abc.htm" ,在后台 模板编辑时只会显示为 "acb",需要在 index…

制作动画或小游戏——CreateJS基础类(一)

前面曾经记录过Canvas的基础知识《让自己也能使用Canvas》,在实际使用中,用封装好的库效率会高点。 使用成熟的库还能对基础知识有更深入的理解,CreateJS是基于HTML5开发的一套模块化的库和工具,有4个模块,github地址在…

java编程能滑动的多行文本框,带自动垂直滚动的多行文本框

带自动垂直滚动的多行文本框在互联网上有很多类似的问题,包括SO,但提出的解决scheme在我的情况下不起作用。 场景:xaml中有一个日志文本框有一些代码隐藏的方法可以完成一些工作,并在这个文本框中添加一些多行(也许就是这个问题)消…