-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3035f73
commit e505ca8
Showing
9 changed files
with
217 additions
and
133 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
import frontmatter | ||
from dev import devto | ||
from codenewbie import codenewbie | ||
from hashnode import hashnode | ||
|
||
file_markdown = sys.argv[1] | ||
|
||
post = frontmatter.load(file_markdown) | ||
|
||
article = {} | ||
article["title"] = post["title"] | ||
article["description"] = post["subtitle"] | ||
article["canonical_url"] = post["canonical_url"] | ||
article["cover_image"] = post["cover_image"] | ||
article["tags"] = post["tags"] | ||
# article['date']=post['date'] | ||
article["published"] = post["published"] | ||
article["body_markdown"] = post.content | ||
if "series" in post: | ||
article["series"] = post["series"] | ||
|
||
print(f"1. dev.to \n2. hashnode.com\n3. codenewbie\n4. medium.com\n") | ||
opt = input("Where you would like to post? (1/2/3/4) : ") | ||
|
||
if opt == "1": | ||
devto(article) | ||
elif opt == "2": | ||
hashnode(article) | ||
elif opt == "3": | ||
codenewbie(article) | ||
else: | ||
print("Invalid Option") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import requests | ||
import json | ||
import sys | ||
|
||
|
||
def codenewbie(article): | ||
|
||
with open("keys.txt", "r") as file: | ||
keys = file.readlines() | ||
|
||
codenewbie_keys = keys[5] | ||
codenewbie_keys = codenewbie_keys.split("codenewbie:")[1].strip() | ||
|
||
API_ENDPOINT = "https://community.codenewbie.org/api/articles" | ||
|
||
""" | ||
data = { | ||
'Content-Type': 'application/json', | ||
'article': { | ||
'title': article['title'], | ||
'description': article['subtitle'], | ||
'canonical_url': article['canonical_url'], | ||
'published': article['published'], | ||
'tags': article['tags'], | ||
'series': article['series'], | ||
'cover_image': article['cover_image'], | ||
'body_markdown': article['content'] | ||
}, | ||
} | ||
""" | ||
|
||
post = {} | ||
|
||
for key in article: | ||
post[key] = article[key] | ||
|
||
dev_keys = keys[0] | ||
dev_keys = dev_keys.split("dev.to:")[1].strip() | ||
|
||
API_ENDPOINT = "https://dev.to/api/articles" | ||
|
||
data = { | ||
"Content-Type": "application/json", | ||
"article": post, | ||
} | ||
print(data) | ||
header = {"api-key": codenewbie_keys} | ||
response = requests.post( | ||
url=API_ENDPOINT, json=data, headers={"api-key": codenewbie_keys} | ||
).json() | ||
|
||
print("The article URL is:", response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import requests | ||
import json | ||
|
||
|
||
def devto(article): | ||
|
||
with open("keys.txt", "r") as file: | ||
keys = file.readlines() | ||
|
||
post = {} | ||
|
||
for key in article: | ||
post[key] = article[key] | ||
|
||
dev_keys = keys[0] | ||
dev_keys = dev_keys.split("dev.to:")[1].strip() | ||
|
||
API_ENDPOINT = "https://dev.to/api/articles" | ||
|
||
data = { | ||
"Content-Type": "application/json", | ||
"article": post, | ||
} | ||
""" | ||
data = { | ||
'Content-Type': 'application/json', | ||
'article': { | ||
'title': article['title'], | ||
'description': article['subtitle'], | ||
'canonical_url': article['canonical_url'], | ||
'published': article['published'], | ||
'tags': article['tags'], | ||
'series': article['series'], | ||
'cover_image': article['cover_image'], | ||
'body_markdown':article['content'] | ||
}, | ||
} | ||
""" | ||
|
||
response = requests.post( | ||
url=API_ENDPOINT, json=data, headers={"api-key": dev_keys} | ||
).json() | ||
if "url" in response: | ||
print("The article URL is: ", response["url"]) | ||
else: | ||
print("The article URL is: ", response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import requests | ||
import json | ||
import sys | ||
|
||
|
||
def hashnode(article): | ||
markdown = sys.argv[1] | ||
|
||
with open("keys.txt", "r") as file: | ||
keys = file.readlines() | ||
|
||
hashnode_keys = keys[3].split("hashnode:")[1].strip() | ||
hashnode_id = keys[4].split("hashnode_id:")[1].strip() | ||
title = str(article["title"]) | ||
subtitle = article["description"] | ||
canonical_url = article["canonical_url"] | ||
cover_image = article["cover_image"] | ||
tags = article["tags"] | ||
published = article["published"] | ||
content = article["body_markdown"].replace( | ||
"\n", "\\n" | ||
) # .replace("\\c", "\c").replace("\r", "\t") | ||
content = "".join(content.splitlines()) | ||
|
||
API_ENDPOINT = "https://api.hashnode.com" | ||
|
||
data = f""" | ||
mutation{{ | ||
createPublicationStory( | ||
input: {{ | ||
title: "{title}" | ||
contentMarkdown: "{content}", | ||
tags: [ | ||
{{ | ||
_id: "56744721958ef13879b94ffc", | ||
name: "General Programming", | ||
slug: "programming", | ||
}} | ||
] | ||
coverImageURL:"{cover_image}" | ||
}} | ||
publicationId: "{hashnode_id}", | ||
hideFromHashnodeFeed:false | ||
) {{ | ||
message | ||
post{{ | ||
title | ||
}} | ||
}} | ||
}}""" | ||
# Work in progress | ||
# data= '{"query":"mutation { | ||
# createPublicationStory( | ||
# input: { | ||
# title: \"'"$title"'\", | ||
# contentMarkdown: \"'"$body"'\" | ||
# tags: [ | ||
# { | ||
# _id: \"56744721958ef13879b94ffc\", | ||
# name: \"General Programming\", | ||
# slug: \"programming\" | ||
# } | ||
# ] | ||
# coverImageURL:\"'"$cover_image"'\" } | ||
# publicationId:\"'"$hash_id"'\", | ||
# hideFromHashnodeFeed:false | ||
# ) { | ||
# message | ||
# post{ | ||
# title | ||
# coverImage | ||
# } | ||
# } | ||
# } | ||
# }' --compressed | ||
# | ||
|
||
header = { | ||
"Content-Type": "application/json", | ||
"Origin": "https://api.hashnode.com", | ||
"Authorization": hashnode_keys, | ||
} | ||
|
||
response = requests.post(url=API_ENDPOINT, json={"query": data}, headers=header) | ||
|
||
print("The article URL is:", response.json()) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.