Do something interesting with python-analyze QQ Chat history (Supplemental)

Source: Internet
Author: User

Before, I wrote this article, using Python to extract the speech time of all the members of the group, and made a simple analysis. First, add the acquisition of a message record for a particular individual group member (here, for example, a small white).

The code is relatively simple, mainly the writing of regular expressions. (Attached: The export of chat file records, please refer to the above mentioned article)

The code is as follows:

# ./9/ -#从QQ聊天数据导出特定人发言的日期时间和发言内容import reimport xlsxwriter# Small white Here's the nickname for the object you want to get data for. For convenience, see the file name of the data export is also clearly workbook= Xlsxwriter. Workbook ('little white. xlsx') Worksheet=Workbook.add_worksheet () worksheet.set_column ('a:a',5) Worksheet.set_column ('b:b',Ten) Worksheet.set_column ('C:c', $) with open ('advanced mathematics. TXT', encoding='Utf-8') asf:s=F.read () # Regular, matching pa across rows= Re.compile (r'^ (\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2}) Small white \ (small white QQ number \) \ n (. *?) \n$', Re. dotall+Re. MULTILINE) Ma=Re.findall (pa,s) # print (Len (MA)) forIinchRange (len (MA)): # Print (ma[i][0]) Date= ma[i][0] Time= ma[i][1] Word= ma[i][2] Worksheet.write (int(i),0, date) Worksheet.write (int(i),1, Time) Worksheet.write (int(i),2, Word) workbook.close () print ("go ahead and look at the new. xlsx file under the folder.")

Do something interesting with python-analyze QQ Chat history (Supplemental)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.