Skip to content

Commit

Permalink
fix: moving from sh to py
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Destructive committed Jan 28, 2022
1 parent 5a7a7bf commit 71ea64e
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 39 deletions.
5 changes: 3 additions & 2 deletions crosspost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function codenewbie()
echo -e "Error...\nFailed to post on dev.to"
fi
}

touch keys.txt body.md temp.md temp.txt
keys=keys.txt

Expand Down Expand Up @@ -187,7 +188,7 @@ if [[ $num -eq 1 ]];then
sed -i "/to:/ s/$/$dev_key/" $keys
fi

python python/dev.py $file
dev

elif [[ $num -eq 2 ]];then

Expand Down Expand Up @@ -215,7 +216,7 @@ elif [[ $num -eq 6 ]];then
sed -i "/codenewbie:/ s/$/$codenbkeys/" $keys
fi

python python/codenewbie.py $file
codenewbie

else
echo "Invalid Input"
Expand Down
Empty file added python/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions python/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
import frontmatter
import dev
import codenewbie

file_markdown = sys.argv[1]

with open(file_markdown,'r') as file:
article = file.read()

post=frontmatter.load(file_markdown)

title=post['title']
subtitle=post['subtitle']
canonical_url=post['canonical_url']
cover_image=post['cover_image']
tags=post['tags']
date=post['date']
publishe=post['published']
article=post.content

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'):
dev.devto(article)
elif(opt == '3'):
codenewbie.codenewbie(article)
else:
print("Invalid Option")
38 changes: 20 additions & 18 deletions python/codenewbie.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import requests
import sys

markdown = sys.argv[1]
with open(markdown,'r') as file:
article = file.read()
def codenewbie(article):

with open('keys.txt', 'r') as file:
keys = file.readlines()
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': {'body_markdown':article},
}

response = requests.post(url = API_ENDPOINT,json=data, headers={"api-key":codenewbie_keys}).json()

print("The article URL is:", response['url'])
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': {'body_markdown':article},
}

response = requests.post(url = API_ENDPOINT,json=data, headers={"api-key":codenewbie_keys}).json()

print("The article URL is:", response['url'])

if(response['url']):
return True
return False
38 changes: 19 additions & 19 deletions python/dev.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import requests
import sys

markdown = sys.argv[1]
with open(markdown,'r') as file:
article = file.read()
def devto(article):
with open('keys.txt', 'r') as file:
keys = file.readlines()

with open('keys.txt', 'r') as file:
keys = file.readlines()

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': {'body_markdown':article},
}

response = requests.post(url = API_ENDPOINT,json=data, headers={"api-key":dev_keys}).json()

print("The article URL is: ",response['url'])
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': {'body_markdown':article},
}

response = requests.post(url = API_ENDPOINT,json=data, headers={"api-key":dev_keys}).json()

print("The article URL is: ",response['url'])
if(response['url']):
return True
return False
55 changes: 55 additions & 0 deletions python/hashnode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import requests
import sys

markdown = sys.argv[1]
with open(markdown,'r') as file:
article = file.read()

with open('keys.txt', 'r') as file:
keys = file.readlines()

hashnode_keys = keys[4]
hashnode_keys = hashnode_keys.split('hashnode:')[1].strip()

API_ENDPOINT = "https://api.hashnode.com"

# 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 = {
# 'Accept-Encoding': 'gzip, deflate',
# 'Content-Type': 'application/json',
# 'Accept': 'application/json',
# 'Connection': 'keep-alive',
# 'DNT': '1'
# 'Origin': 'https://api.hashnode.com'
# 'Authorization': hashnode_keys,
# }
#
#response = requests.post(url = API_ENDPOINT,json=data, headers=header.json())
#
#print("The article URL is:", response['url'])

0 comments on commit 71ea64e

Please sign in to comment.