The second small program developed based on pyqt: campusbbsassistant)

Source: Internet
Author: User

This software is designed to help BBS users in Colleges and Universities easily post messages. Its main functions include logging on to the BBS site, uploading attachments, and posting posts. Due to limited test accounts, the software currently only supports five BBS sites in colleges and universities, including Baiyun Huang He, Shui Mu community, Shui Mu Tsinghua, Yin Shui siyuan, and keyuan star. (If you are willing to provide your account for development and testing, thank you very much. Contact: yysdsyl # QQ.com)

 

 

Software: campusbbsassistant

 

 

Software effect display:

 

 

Implementation:

 

 

Based on the functions of the software, the division of software modules is clear. The following modules are available:

 

1. BBS layout information capturing

2. log on to and log out of the BBS site

3. Upload attachments

4. Post

 

Next we will pick out some worth mentioning parts for each module.

1. layout information capture

 

There is no technical content, that is, regular expression matching, pure physical activity. Among the five BBS sites, the layout information of Baiyun Huang He is the easiest to capture. The layout of shuimu Tsinghua, shuishuishuisiyuan, and keyuan star is nested, which is a little more complicated, but it does not take much effort. The layout information capture in the Shui Mu community is one of the five most troublesome ones, because the source code of all pages in the Shui Mu community is JavaScript (if you are interested, you can check it out ), therefore, you have to parse the JS Code and obtain the layout and URL Information.

 

 

2. log on to and log out of BBS

This module performs a single task, that is, simulating login to log out of BBS and obtaining and maintaining the returned cookie for later modules. Python cookielib, urllib, urllib2 modules can easily complete this task, http://blog.csdn.net/yysdsyl/archive/2009/11/01/4754462.aspx

This article provides relevant code reference.

However, among the five BBS sites, Bai Yunhe has some exceptions. After successful login, it returns cookie information through Js. Therefore, cookielib cannot obtain cookie information, but can only obtain the required cookie information through manual parsing.

 

3. Upload attachments

The attachments Uploaded By Baiyun Huang He and drinking water source are similar. They are uploaded to the corresponding upload area of the layout. After the attachment is uploaded successfully, the URL of the attachment is returned, the user needs to manually copy the URL address to the body of the post. This process is extremely troublesome for the user. This software allows you to upload attachments in batches and then automatically paste the URL address to the body of the article. The attachments of the other three sites are relatively user-friendly. After the attachments are uploaded, the attachments are published directly and automatically appear in the Post. They basically use a template, it seems that it was modified based on the kds upload module.

 

In the upload module, the value of encode is the attachment data. The following two functions are provided, written by a foreign user:

 

Def encode_multipart_formdata (fields, files): <br/> "" <br/> fields is a sequence of (name, value) Elements for regular <br/> form fields. files is a sequence of (name, filename, value) <br/> elements for data to be uploaded as files. <br/> return (content_type, body) Ready For httplib. HTTP instance <br/> failed <br/> PS: This function was wrritten by Wade leftwich first <br/> and modified by James jurack <br/> URL: http://code.activestate.com/recipes/146306/ <br/> "" <br/> boundary = mimetools. choose_boundary () <br/> CRLF = '/R/N' <br/> L = [] <br/> for (Key, value) in fields: <br/> L. append ('--' + boundary) <br/> L. append ('content-Disposition: Form-data; name = "% s" '% key) <br/> L. append ('') <br/> L. append (value) <br/> for (Key, filename, value) in files: <br/> L. append ('--' + boundary) <br/> L. append ('content-Disposition: Form-data; name = "% s";/<br/> filename = "% s" '% (Key, filename )) <br/> L. append ('content-type: % s' % get_content_type (filename) <br/> L. append ('') <br/> L. append (value) <br/> L. append ('--' + boundary + '--') <br/> L. append ('') <br/> body = CRLF. join (l) <br/> content_type = 'multipart/form-data; boundary = % s' % boundary </P> <p> return content_type, body </P> <p> def get_content_type (filename): <br/> "" <br/> return the content type of file. <br/> --------------------------------- <br/> PS: This function was wrritten by Wade leftwich first <br/> and modified by James jurack <br/> URL: http://code.activestate.com/recipes/146306/ <br/> "" <br/> return mimetypes. guess_type (filename) [0] Or 'application/octet-stream'

 

 

4. Post

 

This module has nothing to say about. It is easy to do, that is, to send the text body, title, and so on.

 

 

 

 

 

PS:

 

The program finally encountered some trouble when packaging with py2exe. In the initial version, I used the things in the python httplib2 module. After packaging, it was difficult to use the httplib2 function, google, someone has encountered the same problem, and basically locking is the problem of py2exe, but no solution is found. Later, I tried to completely bypass httplb2 in code implementation and use modules or functions with similar functions to solve the problem.

 

 

 

-------------------------------------------------------------------

 

 

I was also preparing to package a Linux version. I didn't expect that the total size of the package would be more than 100 MB after using cxfreeze. Well, forget it.

 

 

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.