关联的数据表

在phpBB3中导入用户时, 需要处理的有两张表, 一个是 users, 一个是 user_group.

如果是新安装的论坛, 在每次导入之前, 用以下语句初始化:

DELETE FROM phpbb_users WHERE user_id > 47;
alter table phpbb_users auto_increment = 48; DELETE FROM phpbb_user_group where user_id > 48;
DELETE FROM phpbb_user_group where user_id = 0;

需要的最小数据集

对于users表

需要的最小字段为 `user_type`, `group_id`, `user_permissions`, `user_ip`, `user_regdate`, `username`, `username_clean`, `user_lastvisit`, `user_lastmark`, `user_posts`, `user_lang`, `user_timezone`, `user_dateformat`, `user_style`, `user_sig`, `user_occ`, `user_interests`

如果是新安装的论坛, 进需要对这些字段动态赋值: `user_ip`, `user_regdate`, `username`, `username_clean`, `user_lastvisit`, `user_lastmark`, `user_posts`, `user_sig`

对于user_group表

每一个user添加默认注册用户对应的组记录, 对于新安装的论坛, 添加一条对应组2的记录

Python脚本

print("\n" + '######## Start:' + str(i) + ', limit:' + str(limit) + ' ########')
users = tb_user_all.find().sort('registeredAt', 1).limit(limit).skip(i)
for user in users:
try:
with rbcommon.mysqlclient.cursor() as cursor:
if (user['nick'] == 'User Not Found'):
sql = 'INSERT IGNORE INTO `phpbb_users` (`user_type`, `group_id`, `user_permissions`, `user_ip`, `user_regdate`, `username`, ' \
'`username_clean`, `user_lastvisit`, `user_lastmark`, `user_posts`, `user_lang`, `user_timezone`, ' \
'`user_dateformat`, `user_style`, `user_sig`, `user_occ`, `user_interests`) ' \
'VALUES (0, 2, \'\', %s, %s, %s, %s, %s, %s, %s, \'en\', 8.00, \'|Y-m-d| G:i\', 1, %s, \'\', \'\')'
cursor.execute(sql, (
user['ip'],
user['registeredAt'],
user['name'].strip(),
user['_id'].strip(),
user['registeredAt'],
user['registeredAt'],
user['posts'],
'' if (not 'signature' in user) else user['signature']))
else:
lastVisit = 0
if (user['lastLogin'] == ''):
lastVisit = 0
else:
lastVisit = int(time.mktime(time.strptime(user['lastLogin'], '%a %b %d %H:%M:%S %Y'))) if (lastVisit == 0) and (len(user['lastActive']) > 0):
lastVisit = int(time.mktime(time.strptime(user['lastActive'], '%a %b %d %H:%M:%S %Y'))) sql = 'INSERT IGNORE INTO `phpbb_users` (`user_type`, `group_id`, `user_permissions`, `user_ip`, `user_regdate`, `username`, ' \
'`username_clean`, `user_lastvisit`, `user_lastmark`, `user_posts`, `user_lang`, `user_timezone`, ' \
'`user_dateformat`, `user_style`, `user_sig`, `user_occ`, `user_interests`) ' \
'VALUES (0, 2, \'\', %s, %s, %s, %s, %s, %s, %s, \'en\', 8.00, \'|Y-m-d| G:i\', 1, %s, \'\', \'\')'
cursor.execute(sql, (
user['ip'],
user['registeredAt'],
user['name'].strip(),
user['_id'].strip(),
lastVisit,
lastVisit,
user['posts'],
'' if (not 'signature' in user) else user['signature'])) # phpbb_user_group
lastId = cursor.lastrowid
if (lastId == 0):
print('Duplicate ID:>{}<'.format(user['name']))
rbcommon.mysqlclient.rollback()
continue
print(lastId) sql = 'INSERT IGNORE INTO `phpbb_user_group` (`group_id`, `user_id`, `group_leader`, `user_pending`) ' \
'VALUES (2, %s, 0, 0)'
cursor.execute(sql, (lastId)) rbcommon.mysqlclient.commit()
except Exception as e:
print(json.dumps(user))
traceback.print_exc()

.

导入结束后, 需要在后台首页, 重置全站的文章和用户统计数字.

.

phpBB3导入用户的Python脚本的更多相关文章

  1. phpBB3导入帖子的Python脚本

    关联的数据表 在phpBB3中导入用户时, 需要处理的有两张表, 一个是 topics, 一个是 posts.为了方便与原数据关联, 需要在这两个表上新增一个字段并建立唯一索引 ALTER TABLE ...

  2. phpBB3导入版面的Python脚本

    关联的数据表 在phpBB3中导入版面时, 需要处理的有两张表, 一个是 forums, 一个是 acl_groups. 如果是干净的论坛, 可以不保留安装时填入的默认分区和版面, 直接用以下语句初始 ...

  3. zabbix3.4用Python脚本Excel批量导入主机

    1.安装xlrd读取Excel文件 1.1. 下载setuptools-38.2.4.zip,上传至zabbix服务器解压安装,下载地址:https://pypi.python.org/package ...

  4. 普通用户在命令终端使用Python脚本连入校园网

    普通用户在命令终端使用Python脚本连入校园网 想要连入校园网的步骤: 浏览器输入对应的IP地址,输入账号密码连网: 下载对应软件,输入账号密码连网: 而面对没有界面的服务器,而你又没有root权限 ...

  5. ArcGIS使用Python脚本工具

    在Pyhton写的一些代码,用户交互不方便,用户体验比较差,不方便重用.在ArcGIS中可以将用写的Python代码导入到ToolBox中,这样用起来就比较方便了.这里用按要素裁剪栅格的Python来 ...

  6. 用 Python 脚本实现对 Linux 服务器的监控

    目前 Linux 下有一些使用 Python 语言编写的 Linux 系统监控工具 比如 inotify-sync(文件系统安全监控软件).glances(资源监控工具)在实际工作中,Linux 系统 ...

  7. 使用Python脚本强化LLDB调试器

    LLDB是Xcode自带的调试器,作为一个iOS应用开发程序员,平时我在开发应用时会使用LLDB来调试代码.在逆向应用时,也会用到LLDB来跟踪应用的执行过程. LLDB还内置了一个Python解析器 ...

  8. 利用pyinstaller将python脚本打包发布

    之前写了一个小工具,将excel配置表转换为json.xml.lua等配置文件.最近在学习egret,正好需要转换配置文件,刚好就用上了.然而当我想把工具拷到工作目录时,就发愁了.之前我为了方便扩展, ...

  9. python 全栈开发,Day94(Promise,箭头函数,Django REST framework,生成json数据三种方式,serializers,Postman使用,外部python脚本调用django)

    昨日内容回顾 1. 内容回顾 1. VueX VueX分三部分 1. state 2. mutations 3. actions 存放数据 修改数据的唯一方式 异步操作 修改state中数据的步骤: ...

随机推荐

  1. python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性

    python inspect 模块 和 types 模块 判断是否是方法,模块,函数等内置特殊属性 inspect import inspect def fun(): pass inspect.ism ...

  2. detailFormatter bootstrapTable

    detailView : true,//会导致表格最开头多出一列 detailFormatter :function(index, row, element){ var image = '<di ...

  3. Python编译安装遇到的问题

    1.python在make时候报错 Python build finished, but the necessary bits to build these modules were not foun ...

  4. ceil()函数的应用-hdu1065

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1065 题目描述: floor(x)  is the largest integer not great ...

  5. ACM-ICPC Beijing 2016 Genius ACM(倍增+二分)

    描述 给定一个整数 M,对于任意一个整数集合 S,定义“校验值”如下: 从集合 S 中取出 M 对数(即 2∗M 个数,不能重复使用集合中的数,如果 S 中的整 数不够 M 对,则取到不能取为止),使 ...

  6. Nowcoder contest 370B Rinne Loves Graph 【分层图最短路】

    <题目链接> 题目大意: Island 是有一些奇怪的城镇和道路构成的(题目需要,游戏党勿喷),有些城镇之间用双向道路连接起来了,且每条道路有它自己的距离.但是有一些城镇已经被派兵戒严,虽 ...

  7. python之迭代器与生成器

    python之迭代器与生成器 可迭代 假如现在有一个列表,有一个int类型的12345.我们循环输出. list=[1,2,3,4,5] for i in list: print(i) for i i ...

  8. RFC2616-HTTP1.1-Status Code(状态码规定部分—单词注释版)

    part of Hypertext Transfer Protocol -- HTTP/1.1RFC 2616 Fielding, et al. 10 Status Code Definitions ...

  9. XamarinAndroid组件教程RecylerView适配器使用动画

    XamarinAndroid组件教程RecylerView适配器使用动画 为RecylerView使用RecylerViewAnimators组件中提供的适配器动画,需要使用RecyclerView类 ...

  10. UVA 815 Flooded!

    题意:来自:https://blog.csdn.net/lecholin/article/details/70186673 思路: ①数组存每个网格的高度,然后排序,做题时想象为上面的柱状图. ②注意 ...