Skip to content

Commit

Permalink
added ability to switch base urls via env, added gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
Radude committed Oct 26, 2023
1 parent 176a31c commit c458c99
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
venv
.env
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# rentry

<a href="https://rentry.co/"><img width="110" height="110" src="https://rentry.co/static/logo-border-fit.png" align="right" alt="rentry.co markdown pastebin"></a>
<a href="https://rentry.co/"><img width="110" height="110" src="https://rentry.co/static/logo-border-fit.png" align="right" alt="rentry.co markdown paste repository"></a>

[Rentry.co](https://rentry.co) is markdown-powered pastebin/publishing service with preview, custom urls and editing.
[Rentry.co](https://rentry.co) is markdown-powered paste/publishing service with preview, custom urls and editing.

This repository contains a simple script that allows pasting and editing from command line interface.

Expand All @@ -19,6 +19,8 @@ wget https://github.com/raw/radude/rentry/master/rentry -O ./rentry &
pip3 install rentry
```

pip install -r 'requirements.txt'
cp env_example .env
## Usage

```console
Expand Down
2 changes: 2 additions & 0 deletions env_example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BASE_PROTOCOL="https://"
BASE_URL="rentry.co"
16 changes: 10 additions & 6 deletions rentry → rentry.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
from http.cookies import SimpleCookie
from json import loads as json_loads
from os import environ
from dotenv import load_dotenv, dotenv_values

_headers = {"Referer": 'https://rentry.co'}
load_dotenv()
env = dotenv_values()

_headers = {"Referer": f"{env['BASE_PROTOCOL']}{env['BASE_URL']}"}


class UrllibClient:
Expand Down Expand Up @@ -38,13 +42,13 @@ def _request(self, request):

def raw(url):
client = UrllibClient()
return json_loads(client.get('https://rentry.co/api/raw/{}'.format(url)).data)
return json_loads(client.get(f"{env['BASE_PROTOCOL']}{env['BASE_URL']}" + '/api/raw/{}'.format(url)).data)


def new(url, edit_code, text):
client, cookie = UrllibClient(), SimpleCookie()

cookie.load(vars(client.get('https://rentry.co'))['headers']['Set-Cookie'])
cookie.load(vars(client.get(f"{env['BASE_PROTOCOL']}{env['BASE_URL']}"))['headers']['Set-Cookie'])
csrftoken = cookie['csrftoken'].value

payload = {
Expand All @@ -54,13 +58,13 @@ def new(url, edit_code, text):
'text': text
}

return json_loads(client.post('https://rentry.co/api/new', payload, headers=_headers).data)
return json_loads(client.post(f"{env['BASE_PROTOCOL']}{env['BASE_URL']}" + '/api/new', payload, headers=_headers).data)


def edit(url, edit_code, text):
client, cookie = UrllibClient(), SimpleCookie()

cookie.load(vars(client.get('https://rentry.co'))['headers']['Set-Cookie'])
cookie.load(vars(client.get(f"{env['BASE_PROTOCOL']}{env['BASE_URL']}"))['headers']['Set-Cookie'])
csrftoken = cookie['csrftoken'].value

payload = {
Expand All @@ -69,7 +73,7 @@ def edit(url, edit_code, text):
'text': text
}

return json_loads(client.post('https://rentry.co/api/edit/{}'.format(url), payload, headers=_headers).data)
return json_loads(client.post(f"{env['BASE_PROTOCOL']}{env['BASE_URL']}" + '/api/edit/{}'.format(url), payload, headers=_headers).data)


def usage():
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-dotenv

0 comments on commit c458c99

Please sign in to comment.