Lab 4 - MongoDB Blogging App (Using Python)

Build a Blog engine (not the web UI part) using MongoDB and Python on your laptop. It should process a stream (stdin) of blog transactions for one or more blogs. Those transactions include:

post blogName userName title postBody tags timestamp

  • if the blogName blog doesn’t exist, it is created.
  • userName is a quoted string.

  • title is a quoted string.

  • postBody is a quoted string.

  • tags is a quoted string of comma-separated tags, “” if there are none

  • timestamp is included here to aid in testing. Normally it would be automatically generated.

    When the post is added to the DB:

    1. the title, userName, tags, timestamp, and postBody fields are included.
    2. the blogname and title is used to create a unique permalink field that is included:

      • first replace all non-alphanumeric characters in the title with underscores,
      • then concatenate that on the end of the blogname.

      Here’s a Python snippet to do that:

      permalink  = blogname+'.'+re.sub('[^0-9a-zA-Z]+', '_', title)
      

  • the commentBody is added as a comment to the referenced post or comment having the specified permalink in quotes.
  • commentBody is a quoted string.
  • comments do not have tags
  • when the comment is added to the blog, its permalink is set to the current timestamp.
  • if the referenced permalink post or comment doesn’t exist, print an error message to stderr.

  • the post or comment matching that permalink is replaced with a standard post or comment saying “deleted by {userName}”, and a new timestamp is added.
  • none of the other existing entries are removed.
  • if the referenced post or comment doesn’t exist, print an error message to stderr.

  • show blogName Should produce output like this:

    > show politics
      
    in Politics:
      
      - - - -
    	title: This Title has 26-letters!
    	userName: Zorro
    	tags: tag1, tag2, ... // omit tags line if none
    	timestamp: 2018-10-02T11:01:28.425Z
    	permalink: Politics.This_Title_has_26_letters_
    	body:
    	  body contents ...
      
        - - - -
    	  userName: Chico
    	  permalink: 2018-10-02T11:02:28.965Z
    	  comment:
    	    comment contents ...
      
      - - - -
      title: Here we go again?
    	userName: Gummo
    	tags: tag1, tag2, ... // omit tags line if none
    	timestamp: 2018-10-02T11:01:28.425Z
    	permalink: Politics.Here_we_go_again_
    	body:
    	  body contents
      
        - - - -
    	  userName: Harpo
    	  permalink: 2018-11-02T11:02:42.966Z
    	  comment:
    	  	comment contents ...
      
          - - - -
    	    userName: Zeppo
    	    permalink: 2017-11-02T02:12:18.965Z
    	    comment:
    	  	  comment on comment contents ...
      
          - - - -
    	    userName: Harpo
    	    permalink: 2017-11-02T04:15:05.232Z
    	    **comment deleted**
      . . .
    

Extra Credit (5 points)

Add the following transaction:

find blogName searchString

  • searches the post body, tags, and comment portions of all the posts and comments for occurrences of the quoted searchString.
  • searchString must match exactly. That is, wildcards or RegEx’s are not required.
  • if a document containing a match is a comment document, you don’t need to print the document(s) upon which it is a comment. Thus, if it is a comment document you don’t need to indent it.
  • an example search is find politics "dimwit":
in Politics:

  - - - -
	title: The Title has 25-letters!
	userName: Zorro
	tags: tag1, tag2, ... // omit tags line if none
	timestamp: 2018-10-02T11:01:28.425Z
	permalink: Politics.The_Title_has_25_letters_
	body:
	  body contents containing dimwit

    - - - -
	  userName: Chico
	  permalink: 2018-10-02T11:02:28.965Z
	  comment:
	    comment contents containing dimwit

  - - - -
	title: Here we go again?
	userName: Gummo
	tags: tag1, dimwit, tag3, ... // omit tags line if none
	timestamp: 2018-10-02T11:01:28.425Z
	permalink: Politics.Here_we_go_again_
	body:
	  body contents

    - - - -
	  userName: Harpo
	  permalink: 2018-11-02T11:02:42.966Z
	  comment:
	  	comment containing dimwit...

      - - - -
	    userName: Zeppo
	    permalink: 2017-11-02T02:12:18.965Z
	    comment:
	  	  comment on comment contents containing dimwit...
    . . .

What to submit in Canvas

Create a compressed tar file (.tgz) that contains all these:

  1. README.md file explaining how to build, run, and test your application.
  2. All source code (e.g., python, javascript, .sh, .ini).
  3. Remember to use a config.ini file to hold your login and password!

  4. Test data file(s) you used to verify correct operation. These should be input and expected output files included. We should be able to run your code with your input file and produce a matching output file.
$ python lab4 < testfile1.in > grader.testfile1.out 2>&1
$ diff grader.testfile1.out testfile1.out
$

A .in file might look like this:

post blog1 ccp "Welcome!" "this is a new blog" "" 2018-10-01T01:01:01.422Z
post blog1 ccp "My second post!" "this will get deleted" "tagvalue" 2018-10-02T11:01:28.425Z
delete blog1 blog1.2018-10-02T11:01:28.425Z ccp 2018-10-03T05:41:11.842Z
comment blog1 blog1.2018-10-01T01:01:01.422Z ccp "this is the commentbody" 2018-10-03T03:31:52.432Z
...