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. qtreewidget 显示保存xml文件

    此文是读取和存储已知结构的xml,对于未知结构的xml,可以用递归方法读取和遍历.可参考文章:Qt遍历不规则树的节点. 1.QTreewidget设置 //折叠图标(三角图标)换成自定义图标 ui-& ...

  2. CF573E Bear and Bowling

    题目 我们设\(f_{i,j}\)表示前\(i\)个数中选\(j\)个的最大值. 那么显然有\(f_{i,j}=max(f_{i-1,j},f_{i-1,j-1}+j*a_i)\). 这个东西我们首先 ...

  3. thinkPHP三级城市联动

    html+js: <!doctype html> <html lang="en"> <head> <meta charset=" ...

  4. HNUSTOJ-1009 格雷码

    1009: 格雷码 时间限制: 1 Sec  内存限制: 128 MB提交: 90  解决: 78[提交][状态][讨论版] 题目描述 对于给定的正整数n,格雷码为满足如下条件的一个编码序列:(1) ...

  5. how to install protobuff python

    当前环境: operate system: Ubuntu 14.04.1 LTS protoc --version: libprotoc 2.5.0    protocol-buffers versi ...

  6. SpringBoot_03mybatisPlus

    注意: mybatisPlus默认加载resources下的mapper文件夹下的xml文件 默认将数据库表的字段用驼峰标识转换成实体类的属性 官方网站: https://mp.baomidou.co ...

  7. jQuery中$()可以有两个参数

    jQuery(expression, [context]) 返回值:jQuery 概述 这个函数接收一个包含 CSS 选择器的字符串,然后用这个字符串去匹配一组元素. jQuery 的核心功能都是通过 ...

  8. java程序员究竟应该掌握点什么

    JAVA程序设计(基础部分) JAVA程序设计(专题)

  9. 几个有关FPGA的概念

    <数字设计——原理和实践>(John F.Wakerly)的书 FPGA同步时钟设计 简单说就是 一个系统中(或系统中的一部分)都采用同一个时钟触发.系统中的(D)触发器全部都连接到一个时 ...

  10. Taro -- 文字左右滚动公告效果

    文字左右滚动公告效果 设置公告的左移距离,不断减小,当左移距离大于公告长度(即公告已移出屏幕),重新循环. <View className='scroll-wrap'> <View ...