Taught you how to use Python analyze micro-channel chats

Before you begin, briefly say why my writing this article?

In order to develop new customers, the company's customer service leadership arrangements have added a lot of micro-letter groups, collecting target customer contacts in the group.

However, they collect customer information in a manner very original: look in the micro-channel group group chat records -> Find phone numbers sent by the client -> Copy -> Open house APP -> Fill out the form -> Paste Customer phone number -> Submit -> continue to look at a group chat record .
so it goes on ad infinitum inefficient and boring.
I think the customer service small sisters, certainly very happy to do this work.

So I suggested to the leadership, use the code to do this work.
At present, the above process I've used this code to achieve, in order to achieve the recording process, there is this article.

We hope to meet similar needs you can help.

Article directory

  1. Need to use the tools introduced
  2. Back up phone data and export data micro-channel chats
  3. See DB Browser using micro channel chat data
  4. Chat data read Python
  5. to sum up

1. The need to use tools

As the saying goes, we must first of its profits right tools, are often able to do more with less.
Tools used here are:

name Remark
the iPhone Sorry, I do not have Android phones, all has not been tested on Android machine
iTunes software For the iPhone backup data, backup time, sure to select "No Encryption" backup, otherwise the data can not be read
iPhone Backup Extractor To derive micro-channel database, although it is free software, but its free feature here has been good enough
DB Browser for SQLite Free database visualization software used to view sqlite database
Python 3.7 os, sqlite3, re, pymysql, emoji

2. Back up phone data and export data micro-channel chats

Back up phone data to iTunes 2.1

With a data cable to connect iPhone to your computer, open iTunes for backup.
Do not check the "Encrypt backup"

Exporting data chat 2.2

This step requires the help of a software the iPhone Backup Extractor .

While the software fee, but the free function for us has been good enough.
Open this software, you can see the following interface:

We can see by the chart:
the left is a list of the iPhone has backed
the right of choice expert mode, wait a minute after, you will see the software right area shows the directory structure of the backup file.

So, what we need to back up files that? Where is it?

We need to export the file is: MM.sqlite,WCDB_Contact.sqlite

Wherein the MM.sqliterelevant data is stored chat micro-channel, WCDB_Contact.sqlitea micro-channel data associated contact.

File path is: Applications/com.tencent.xin/微信名称MD5/DB/

According to label pictures, check these two files, and then click the Extract selectedbutton to export the file.
Free version of the software, before exporting the file, you need to wait 10s.

The exported file very fast, almost no wait. This time open the desktop, you can see the file after derived.

3. DB Browser view micro channel chat data

First install the database visualization tool DB Browser for SQLite, click download

open the software, click to open the database

file after the selected export MM.sqlite:

After opening the file, click browse data , then you can quickly switch between different tables in the drop-down box.
Among them, the Chat table at the beginning, is stored chats table. MessageField is chat.

Then, we'll open another file WCDB_Contact.sqlite:

Switch to Friend this table, see the following field.
Among them, dbContactRemarkthe field should be the contact notes;
userNameis the name of the contact of the micro channel, wherein names with @chatroom , and that this is a micro-channel group chat;

Well, now we have found a micro-channel chats, also found a micro-channel contacts, we can begin the process with Python.

4. Read chat content with Python

Implementation process is very simple, I read your code, a total of less than 100 lines, so the code would not stick out, because writing sucks - -
simply said that under the idea of it.

  1. Connecting the two exported database.
  2. Loop through the tables.
  3. Traversing each chat content, and wherein expression matching telephone number with n.
  4. If the strip presence chat phone number, write their own database has fields written telephone number , micro-channel nickname , chat content , the transmission time

Probably more than that.

5. Summary

Realize the whole process is quite fast, it took about half a day.
Although the code is simple, but real company to save a lot of labor costs, still quite rewarding.

My own experience: To observe life around, find the section in which the repeated labor, and to optimize the program, and perhaps this is where the fun programmer.

I have a public number, " brush a problem every day ," Tell me what troubles attention to the next chant, occasionally presented front and Python learning materials.

Guess you like

Origin www.cnblogs.com/guohaojintian/p/11608716.html