GithubHelp home page GithubHelp logo

dailybruin / meow Goto Github PK

View Code? Open in Web Editor NEW
52.0 13.0 14.0 30.84 MB

Daily Bruin's homemade social media manager

License: GNU Affero General Public License v3.0

Shell 1.52% Python 48.15% HTML 1.13% CSS 4.28% JavaScript 44.20% Dockerfile 0.61% Procfile 0.10%
social-media facebook twitter journalism internal-tools django python

meow's Introduction

meow Updates

Daily Bruin's Twitter and Facebook post scheduler

Technologies Used

  • Docker is our way of putting the code for meow in "containers" so you can run it the same on any machine.

Frontend

  • React is a popular JavaScript library for building user interfaces.
  • Redux is a library for maintaining a global state across the entire frontend.

Backend

  • Django is a Web framework that makes working with databases easier!
  • Celery is a task scheduler that runs certain "tasks" at certain intervals.

Structure

.
├── Dockerfile
├── LICENSE
├── Procfile
├── Procfile.dev
├── docker-compose.yml
├── entrypoint.sh
├── meow
│   ├── manage.py
│   ├── frontend
│       └── src
│   ├── meow
│       └── settings.py
│   ├── scheduler
│   ├── ... all other django apps
│   ├── static
│   └── templates
├── readme.md
└── requirements.txt

Getting Started

0. Grab this repo

Clone the repository.

git clone https://github.com/daily-bruin/meow.git
cd meow

1. Shortcut: init-script

To make this whole process easier, we have a script which will run all the steps except npm run watch. Note: the script may pause at certain points to prompt you for secrets or environment variables. If you are part of Daily Bruin, ask the Internal Tools Editor for these values since we have accounts for those set up already.

./init_script.sh

If you get an error saying cannot connect to docker daemon, you may need to run docker commands with sudo. Try calling the sudo version of the init_script.

./sudo_init_script.sh # Only run if the ./init_script.sh did not work.

Once you run this, just run docker-compose up in one terminal tab and npm run watch in another. Then go to localhost:5000 and you should see 1 of several random cats pics :D (and the login page). Now you are done and you can skip all the other steps.

2. Compiling the frontend

Since the redesign for meow is done with React, we need a way to compiled all that code into something that Django can recognize and (more importantly) serve to our user!

First, increase max inotify watchers.

Then, open up a separate Terminal run the command:

npm run watch

npm run watch will recompile the code everytime you make a change! If you don't like this, you can also run npm run build every time you change your code.

3. Check it out!

Point your browser to localhost:5000. Login with your Daily Bruin slack.

4. Connect Social Media Accounts

Navigate to localhost:5000/manage/, and click on "Twitter/Facebook accounts". Make sure you're an admin for the Facebook page you want to connect to and click "Connect with Facebook"! Follow the steps on when you're redirected to Facebook. At the end, you will be prompted to choose a section and a page. Click on the dropdown for "Choose a section" and click on the section Test. Then click on the dropdown for "Choose a page" and click on the Facebook page you want to connect to. Once you click "Connect," you can send posts to Facebook with meow!

The next step is to connect your Twitter account to meow. Head back to localhost:5000/manage/. Ensure that you're logged in to the Twitter account you wish to post to or else you might end up posting to your personal Twitter! Click "Connect with Twitter" and then "Authorize app." When prompted to "Choose a section," select Test. After clicking "Connect," you can begin sending meow posts Twitter.

5. Send a Post!

At localhost:5000, you can begin sending meows. Click "New" in the top right, and fill in the fields. A slug is a relatively unique string used in the newsroom to identify stories in production (e.g., a story about cats could be called news.breaking.meowisdown).

6. Create a Superuser

Superusers have access to Django's admin side. The admin side allows you to access most of the database through a nice UI.

docker-compose run web meow/manage.py createsuperuser

You can use any email and password. For example, you can set username=admin, email=[email protected], and password=admin123.

Then navigate to localhost:5000/admin/. THE TRAILING SLASH IS REQUIRED. Login with the username and password from the previous step and now you can access the admin side.

Adding A Database Field

In Django, if you want to add fields to your database, you would add a field to the corresponding model (each of which represents a table) in models.py. Once you finish adding your attributes, you will need to run makemigrations so django will create code to update the underlying database table headers appropriately.

docker-compose run web meow/manage.py makemigrations # django makes a script to update database headers
docker-compose run web meow/manage.py migrate        # django runs all those scripts it made
docker-compose up --build

Django Shell

The manage.py shell allows you to run any python code in an interactive shell!

In order to access this shell, run docker-compose run web ./meow/manage.py shell. Then a prompt like this should show:

Python 3.6.9 (default, Nov 15 2019, 03:26:27)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>

Useful Examples

  1. Create SMPost (or an instance of any model)
>>> from scheduler.models import *
>>> p =SMPost.objects.create(slug="test")
>>> print(p)
test
>>>
  1. Get all SMPosts (or an instance of any model)
>>> from scheduler.models import *
>>> posts =SMPost.objects.all()
>>> print(posts)
<QuerySet [<SMPost: test>, <SMPost: test>, <SMPost: a>, <SMPost: b>, <SMPost: test>]>
  1. Find and delete a particular SMPosts (or an instance of any model)
>>> from scheduler.models import *
>>> post = SMPost.objects.get(id=number_in_the_url_in_the_edit_meow_page)
>>> post.delete()

Linting

We use a combination of eslint and prettier for our linting and code formatting.

With a few exceptions, we follow the Airbnb JavaScript guide.

License

Meow is released under GNU AGPLv3. See LICENSE for more details.

Though not required, if you use this software or would like to contribute to its development, please let us know by emailing us at [email protected]. We'd love to know what it's being used for, especially if it's at another college newspaper.

meow's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

meow's Issues

Build OAuth tool

For the future: build something to ease getting/adding credentials to the admin. Maybe something like this.

Validate URLs

To help make sure they'll send (mostly non-obvious issues). Like having spaces before and after URLs.

Validate input

I kinda ignored this for now. We need to validate input from the user forms and check that the post has not already been sent.

I think django has things to help with this

Todo list

  • Handle errors with sendposts (and store them properly). For now, just keep trying to send each post until it sends. See #4 for later plans
  • Make a frontend UI
  • Put test credentials in readme
  • Upload to a server and configure cron
  • Revoke test account credentials
  • Create installation instructions
  • Make open-source

Quick Edit Tweets/Posts

Kenny Sherman brought up this idea. It would be cool if we could quick edit tweets from the dashboard without entering full tweet editing mode. Not a priority.

Create a settings table

setting_name, setting_value

So we can store things like defaults and not screw up the other tables

Add cats

I'm not sure how we got this far without adding a picture of a cat. This needs to happen.

Add a preview for the image posted

Would be nice to have a preview of the image that will be used for the post, or even make it possible to customize the image selector/image on a per post basis. This will require re-working the way scraping is done.

Notes field for posts

Sports editor David Gottlieb has requested that a notes field be added for each post so that the social media team can review any specifics regarding the posting schedule

Make a create account form

  1. Add a permission (create_account)
  2. Make the template/view to create an account
  3. Send the person an email with their randomly generated password

This will make it easier for add new accounts and make sure every account has a first_name/last_name and a good password

Also: make them change their password on first login. Not really necessary though. Maybe we can just use the password reset form for this stuff...

Handle errors properly

The site will, at some point, shut down while meow is trying to work. Make sure it can handle errors properly.

@omniaura @thecalvinchan how do you think we should handle posts when the site is down? Not post it? Send an admin a message? Post it anyway? Wait 30 min then do the other things if it's still not up?

Fix slack timestamps

The time meow is reporting on Slack looks like a UTC time instead of the set timezone. Needs a fix.

Make sending posts more robust

Right now, it stumbles and screws up other posts when it finds a non-ASCII character in the links. It should just affect the post itself and nothing else.

Improve UX to mitigate human error

The UI is not very intuitive in helping users figure out which day posts are scheduled. Could add a huge "Today" / "Tomorrow" label on the page to make it super obvious, but other ideas welcome.

"Post Now button" with Confirmation Dialog

Posts which are Readied should have a button that allows them to post immediately, with a confirmation dialog showing the message and everything to be sent out. The permission also needs to be set to Copy only.

Tasks

  • Post now button
  • Confirmation Dialog
  • Give permissions to Copy

Fix bug where meow is unstable when no section is selected

When no section is selected, meow gives an error and stops execution of the cron job. This stops some posts from sending completely until the post without a section is fixed/sent/cleared somehow.

Two ways to fix this:
(1) Catch and log errors from sending an individual posts (here a catch-all might be appropriate) so that if there's one bad post in the pipeline, it won't screw up anything else
(2) Make sure posts either (a) send correctly without a section (i.e. don't send) or (b) can't be approved for publishing without a section

Handle errored out meows more gracefully

When a scheduled post enters an error state (scheduled late/encountered some error) and is not sent, it is currently impossible to recover. This case should be handled better, and the post should ideally be unscheduled (either via a new switch, or one of the existing toggles) and editable for the user to make changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.