w

29.4. __main__ — Top-level script environment — Python 3.6.1 documentation  https://docs.python.org/3/library/__main__.html

D:\pyTOgo\mongoTrans.py

from tool import *
import re '''
危险区,操作不可逆
开始--》
'''
# 批量删除
# deleteMany({'spiderDate': '20180903'}, 'todayUrls')
'''
危险区,操作不可逆
结束《--
'''
'''
以下为
可逆操作
''' # 更新日期字符串冗余- .replace('-', '')
# 更新website字段冗余 .replace('URL:', '')
# cleanData = selectToDic('_id', 'todayUrls', fields={'webSite': 1, 'spiderDate': 1})
# cleanData = selectToDic('_id', 'todayUrls', fields={'Base64parse2times': { '$exists': True}})
'''
collection_name = 'todayUrls'
cleanData = selectToDic('_id', collection_name, fields={'url': 1}, where={'spiderDate': '20180906'})
delIds = []
for i in cleanData:
_id = i
item = cleanData[i]
url = item['url']
pathTag = 'cnhan.com/pinfo/'
# 通过正则删除
if pathTag in url and re.match('^http://www.cnhan.com/pinfo/\d+\.html$',
url) is None:
print(_id, url)
deleteOne({'_id': _id}, collection_name)
''' def improve():
cleanData = selectToDic('_id', 'todayUrls', fields={})
for i in cleanData:
_id = i
item = cleanData[i]
spiderDate = item['spiderDate']
updateOneIdKV(_id, 'spiderDate', spiderDate.replace('-', ''))
print('improve', _id)
if 'webSite' in item:
webSite = item['webSite']
updateOneIdKV(_id, 'webSite', webSite.replace('URL:', '')) def uniqueUrlSpiderDate(collectionMame='todayUrls'):
'''
当日url + spiderDate留其一
:return:
'''
spiderDate_url_set = {}
cleanData = selectToDic('_id', collectionMame, fields={'spiderDate': 1, 'url': 1})
for i in cleanData:
_id = i
item = cleanData[i]
url, spiderDate = item['url'], item['spiderDate']
k = url + spiderDate
if k not in spiderDate_url_set:
spiderDate_url_set[k] = []
spiderDate_url_set[k].append(_id) save_id_l = []
for k in spiderDate_url_set:
save_id_l.append(spiderDate_url_set[k][0])
for i in cleanData:
_id = i
if _id not in save_id_l:
deleteOne({'_id': _id}, collectionMame)
print('uniqueUrlSpiderDate', _id) if __name__ == "__main__":
improve()
uniqueUrlSpiderDate()
uniqueUrlSpiderDate('siteUserPage') D:\pyTOgo\dataAppend.py
from tool import RandomString, selectToDic, updateOne
from mongoTrans import improve, uniqueUrlSpiderDate
from bs4 import BeautifulSoup
import requests, time, json, random cleanDbSwitcher = True if 7 > 9 else False
if cleanDbSwitcher:
improve()
uniqueUrlSpiderDate()
uniqueUrlSpiderDate('siteUserPage') a.py
def fa():
  pass
def fa2():
  pass
fa2()
b.py
import fa from a 没有
if __name__ == "__main__":
则执行fa2()

												

__main__ — Top-level script environment的更多相关文章

  1. PAT (Top Level) Practise 1008 Airline Routes(Tarjan模版题)

    1008. Airline Routes (35) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Given a ...

  2. invalid nib registered for identifier (重用符) - nib must contain exactly one top level object which must be a UITableViewCell instance'

    通过xib创建cell的时候 一定要注意!!! 这个错误是在这个xib中在View同一层级出现了其他的控件,检查一下xib中左边的层级关系,让cell的view是唯一的控件就可以了,否则一执行 就会提 ...

  3. 什么时候需要交换Top Level ?

    什么时候需要交换Top Level ? 上一篇中提到,如果采用仿真的时候,运用门级仿真就需要进行顶层交换,RTL仿真不需要,那么什么时候需要呢? QuartusII 向下包含,在Project Nav ...

  4. 编译openwrt时报错:fstools-2018-01-02-11efbf3b/libfstools/overlay.c: At top level: cc1: error: unrecognized command line option '-Wno-format-truncation' [-Werror]

    1. 详细错误信息 [ 11%] Building C object CMakeFiles/fstools.dir/libfstools/overlay.c.o/home/jello/openwrt/ ...

  5. top level element is not completed

    今天在使用IDEA配置springmvc文件时,出现类似在Android studio 中样式文件报top level element is not completed错,郁闷极了,找了好久 才找到解 ...

  6. 解决Cannot find config.m4 Make sure that you run '/home/php/bin/phpize' in the top level source directory of the module

    oot@DK:/home/daokr/downfile/php-7.0.0/ext/mysqlnd# /home/php/bin/phpizeCannot find config.m4. Make s ...

  7. docker容器里面执行top报“TERM environment variable not set.”

    解决: [hadoop@master ~]$ docker exec -ti 6eca7d27a988 /bin/bashroot@6eca7d27a988:/# topTERM environmen ...

  8. swift错误 Expressions are not allowed at the top level

    ``` ... earlier we said top-level code isn't allowed in most of your app's source files. The excepti ...

  9. 安装openssl 扩展的时候出现Cannot find config.m4. Make sure that you run '/usr/local/php/bin/phpize' in the top level source directory of the module的解决方法

    进入php源码包目录:cd /usr/local/php-5.6.25/ext/openssl 执行命令:  cp ./config0.m4 ./config.m4 即可

随机推荐

  1. P3984高兴的津津

    这道题的标签是并查集,但其实是一个并查集思想的模拟题. 被算法标签迷惑了,一直在想怎么存f[],然后怎么查找,但发现其实很难去做.然后就发现其实就是做一个选择就可以了:拿AU的第i次包含在i-1次里, ...

  2. [LeetCode] 39. 组合总和

    题目链接 : https://leetcode-cn.com/problems/combination-sum/ 题目描述: 给定一个无重复元素的数组 candidates 和一个目标数 target ...

  3. 100行代码撸完SpringIOC容器

    用过Spring框架的人一定都知道Spring的依赖注入控制反转;通俗的讲就是负责实例化对象 和 管理对象间的依赖 实现解耦. 我们来对比两段代码: UserController{ UserServi ...

  4. Xdex(百度版)脱壳工具基本原理

    [原创]Xdex(百度版)脱壳工具基本原理作 者: sherrydl时 间: 2015-12-13,10:52:45链 接: http://bbs.pediy.com/showthread.php?t ...

  5. jquery data的用法

    jquery data和 jquery attr, js getAttribute 有着本质的区别,并且无法用$(el).data('property')的方法,去获取$(el).attr('data ...

  6. vue(js)点击目标div以外区域将目标div隐藏

    今天开发新项目的时候,有个需求,点击一个div 展示出个弹出窗 弹出窗标题的颜色要跟点击的div图标颜色一致, 所以这就需要我遍历一下多个数据, 然后需要点击弹出div的外部其他区域,隐藏这个div. ...

  7. logname - 显示用户登录名

    总览 (SYNOPSIS) logname [OPTION]... 描述 (DESCRIPTION) 显示 当前用户 的 名字. --help 显示 帮助信息, 然后 结束. --version 显示 ...

  8. Linux 安装 Composer

    Linux 安装 Composer  入门 练习环境: 虚拟机:Oracle VM VirtualBox. 系统:CentOS 7. 安装方式一: 参考网址:https://learnku.com/c ...

  9. vue开发知识点总结

    一.vue介绍 Vue.js 是一套构建用户界面(UI)的渐进式JavaScript框架,是一个轻量级MVVM(model-view-viewModel)框架. 二.数据绑定 最常用的方式:Musta ...

  10. Markdown的使用和计算机基础

    TOC] 一级标题 这不是开玩笑 你问我为什么? 粗的才好(滑稽) 什么!明明有人推我 ==一闪一闪亮晶晶== 我上面有人^人在这^ water?H~2~O(下标) hello world! hell ...