For items I and II, you would use the list
API endpoint for whichever type of object you're looking up and then filter that list on whatever criteria you're using.
For example, to list the domains which contain 'zeroshotlearning.app':
import requests
TOKEN = 'YOUR_TOKEN_HERE'
endpoint = 'https://my.opalstack.com/api/v1/domain/list/'
searchfor = 'zeroshotlearning.app'
searchin = 'name'
headers = {'Authorization': f'Token {TOKEN}', 'Content-type': 'application/json'}
objects = requests.get(endpoint, headers=headers)
matches = [o for o in objects.json() if searchfor in o[searchin]]
The results will then be in the matches
variable.
To use this technique for other types of objects, change the following:
- Change
endpoint
to the API endpoint for the objects you want to retrieve
- Change
searchfor
to the text that you're searching for.
- Change
searchin
to the value that you're searching in.
The various API endpoints and the values they return are documented here.
For item III, I recommend that you use the latest version of Python that is compatible with your operating system. You can download Python from python.org.
For item IV, Python supports JSON natively so there is nothing you need to download.
For item V, if you want to mark read and/or delete all of your emails for all of your mailboxes with Python then you'll need to use the Python imaplib
library.
For example, to delete all of the mail in the inbox for a mailbox named 'mymail':
import imaplib
mailbox = 'mymail'
mail_password = 'your mailbox password here'
mail_server = 'imap1.de.opalstack.com' # or 'imap1.us.opalstack.com'
mail_folder = 'INBOX'
M = imaplib.IMAP4_SSL(mail_server)
M.login(mailbox, mail_password)
M.select(mail_folder)
typ, data = M.search(None, 'ALL')
for msgid in data[0].split():
M.store(msgid, '+FLAGS', '(\\Deleted)')
M.expunge()
M.close()
M.logout()
Note that this script will permanently delete mail when it runs. To learn more about imaplib
see: