Skip to content

Commit

Permalink
fix: added python script for codenewbie
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Destructive committed Jan 8, 2022
1 parent ee4c8ed commit fff2b2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
14 changes: 12 additions & 2 deletions crosspost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ read -p "Where you want to cross post to? " num

if [[ $num -eq 1 ]];then

python dev.py
if [[ -z $(sed -n -e 's/.*to://p' $keys) ]];then
read -p "Enter the dev.to API key : " dev_key
sed -i "/to:/ s/$/$dev_key/" $keys
fi

python python/dev.py $file

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

Expand All @@ -205,7 +210,12 @@ elif [[ $num -eq 5 ]];then

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

codenewbie
if [[ -z $(sed -n -e 's/.*codenewbie://p' $keys) ]];then
read -p "Enter the codenewbie API key : " codenbkeys
sed -i "/codenewbie:/ s/$/$codenbkeys/" $keys
fi

python python/codenewbie.py $file

else
echo "Invalid Input"
Expand Down
23 changes: 23 additions & 0 deletions python/codenewbie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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()

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'])
12 changes: 6 additions & 6 deletions dev.py → python/dev.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import requests
import sys

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

with open('keys.txt', 'r') as file:
keys = file.readlines()
Expand All @@ -11,13 +13,11 @@

API_ENDPOINT = "https://dev.to/api/articles"

source_code = countriesStr

data = {
'Content-Type': 'application/json',
'article': {'body_markdown':source_code},
'article': {'body_markdown':article},
}

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

print("The article URL-id is:%s"%response.get("id"),response.get("created_at"))
print("The article URL is: ",response['url'])

0 comments on commit fff2b2c

Please sign in to comment.