Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main site publish functionality #40

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Conversation

changyang-liu
Copy link
Collaborator

This pull request enables publishing to the Daily Bruin main site through WordPress REST API from Kerckhoff. Includes:

  • HTML article generation from AML
  • Image uploading
  • Retrieving tags and authors from Daily Bruin

Change the .env file to specify the desired URL and credentials for publishing. Currently set to DB test site.

changyang-liu and others added 30 commits January 15, 2020 21:24
Currently beautiful soup is used to get headlines from articles
Before, the type hint for content was dict, even though
it should actually be list
Currently only has tests that do not require kerckhoff packages, google drive,
or Wordpress POST requests. These other tests will be added later
The return data provides data allowing posts
to be deleted in tests
String concatenation creates too much unnecessary copying
- Add logger for kerckhoff module
- Replace print statements with log statements
- Remove unnecessary print statements
@changyang-liu changyang-liu changed the title Cliu/wordpress Main site publish functionality Feb 5, 2021
Copy link
Member

@DumboOctopus DumboOctopus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to submit this review a long time ago

\
@@ -0,0 +1,168 @@
import tempfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file still used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the python tempfile package used in image uploading

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it's not used in models.py anymore so I'll remove it

MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you use the wordpress docker container and/or do you think it would be ok to use the docker container instead of the fake mainsite

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use the wordpress docker container. We added this a long time ago so I don't quite remember what exactly we were planning. I think I should be able to remove it

@@ -0,0 +1,159 @@
import tempfile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file might have been created accidently

@@ -6,3 +6,9 @@ class GoogleDriveNotConfiguredException(APIException):

def __init__(self, package):
self.detail = f"Google Drive is not yet configured for {package.slug}."

class PublishError(APIException):
status_code = 400
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I feel like it might be more of a 500 error since the server was unable to fulfill a valid request (400 means request was bad)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's hard to say, because some of them are due to invalid AML, and others are because the server failed to do something. I think I'll add an argument to specify the error code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh I see. Yeah in that case I think an argument would be good

if(file.file_name == "data.aml"):
json_data = file.data
if("jpg" in file.file_name or "jpeg" in file.file_name
or "png" in file.file_name):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be ok if we just checked if the file ended with jpg, jpeg or png? (there might be some built in python package that can do that for us). The reason is because this could possibly lead to us uploading files like "png_list.txt" to wordpress' media library and that might fail causing the whole publish operation to fail.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I'll use the python os package for that. I don't remember if I only allow jpg, jpeg and png because DB only uses those file types, or if I simply forgot to include more. Do you know if kerckhoff should be able to support other image extensions as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing they would want to have in the future is gifs sometimes. However, there some changes we need to make to aws uploading code to support gifs so for now we can leave it out

Copy link
Member

@DumboOctopus DumboOctopus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just the merge conflict but besides that good to go!

for chunk in res.iter_content(chunk_size=1000):
f.write(chunk)
headers = self.basic_auth_header
headers["Content-Disposition"] = f"form-data; filename={file_name}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small thing but technically modifying headers will modify self.basic_auth_header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants