Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Latest commit 78d24dd May 2, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
social_network Update May 2, 2019
.gitignore Initial commit Feb 4, 2017
.travis.yml Refactor started Mar 14, 2018
LICENSE Initial commit Feb 4, 2017 Update Mar 11, 2017 Refactor started Mar 14, 2018
requirements.txt Refactor started Mar 14, 2018 Fix tests Mar 14, 2018 Refactor started Mar 14, 2018


Today we're going to build a clone of a social network (really similar to the blue bird one, but keep it a secret).

As any other social network we're going to have different types of Posts. All these different types of Posts should inherit from the parent Post class:

  • TextPost: Just a simple text post. Should be constructed as TextPost(text="Post Text").
  • PicturePost: A post containing text and the URL of a picture: Should be constructed as PicturePost(text="Post Text", image_url="").
  • CheckInPost: A post containing text and coordinates of the user's position. Should be constructed as CheckInPost(text="Post Text", latitude="40.741895", longitude="-73.989308").

Rmotrgram also has users. A user is a simple class that can be created as: User(first_name="John", last_name="Smith", email="").

Creating posts

Posts are going to be created and then assigned a user. Once we have our user and post created, we're going to use the add_post method from the user class. add_post should add the post to the user's list of posts, and assign that user to the post. Example, to create a text post for our user John, we'll do something like:

john = User("John", "Lennon", "")
text_post = TextPost("All you need is love!")
text_post.user == None  # Important! Since the post has no user yet, the user attribute should be None.


text_post.user == john  # Important!
>>> 1

As you can see from our previous example, a post is created without a user. It's an "orphan" we might say. By default when a post is created it's user attribute is None. But once we add that post to a user using add_post(), the post's user attribute should be updated, and the post should be added to the user's list of posts.

Following users

Users will be able to follow other users. The follow method is super simple:

john = User("John", "Lennon", "")
paul = User("Paul", "McCartney", "")

>>> [<User: "Paul McCartney">]

A user's timeline

This should be almost exactly like twitter. A user will have a timeline, that's just a list of posts created by other users that we're following, sorted by datetime (most recent first).

john = User("John", "Lennon", "")
paul = User("Paul", "McCartney", "")
george = User("George", "Harrison", "")


paul.add_post(TextPost("Post 1"))
george.add_post(TextPost("Post 2"))
paul.add_post(TextPost("Post 3"))

>>>[[<User: "Paul McCartney">], [<User: "George Harrison">]] # John is following Paul and George

>>> [<TextPost: Post 3>, <TextPost: Post 2>, <TextPost: Post 1> 

Important: A user's timeline should only include posts from the users they are following.

Reading Posts

Finally, one of the most interesting use cases of this project is going to be realted to the "visual representation" of the posts. It's a great example of Polymorphism. The concept is simple. If I try to print different types of posts, I'm going to get different representations. Example:

john = User("John", "Lennon", "")
text_post_1 = TextPost("All you need is love!")
picture_post_2 = PicturePost("Check my new submarine.", image_url='')
checkin_post_3 = CheckInPost("At Abbey Road Studios", latitude="19.111", longitude="-9.2222")

John Lennon: "All you need is love!"
  Friday, Feb 03, 2017

John Lennon: "Check my new guitar"
  Pic URL:
  Friday, Feb 03, 2017

John Checked In: "At Abbey Road Studios"
  19.111, -9.2222
  Friday, Feb 03, 2017

(check tests to see more examples)

You can’t perform that action at this time.