Skip to main content

No project description provided

Project description

interpals-api

This Python library provides a simple HTTP API for working with the website https://interpals.net/. It includes:

  • retrieving data by user identifier
  • listing visitors
  • searching for users by criterions
  • viewing and sending messages, deleting chats
  • listing, adding and removing friends
  • listing albums and pictures

Basic example:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')
api = Api(session)

user_info = api.profile('someuser')
print(user_info)

Since version 2.1 it supports asynchronous calls for each api method. Below there is a brief asynchonous example:

from interpals_api import SessionAsync, ApiAsync

session = await SessionAsync.login('yourusername', 'yourpassword')
api = ApiAsync(session)

user_info = await api.profile('someuser')
print(user_info)

Installation

pip install interpals-api

Examples

Basic example to retrieve user info:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')
api = Api(session)

# This gives info of the user with the link: https://www.interpals.net/someuser
user_info = api.profile('someuser')

Dump and load session object:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')

# Save session into a file
with open('session.json', 'w') as f:
    session.dump(f)

# Load session from the saved file
with open('session.json') as f:
    session = Session.load(f)

Viewing and searching for users:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')
api = Api(session)

# Viewing a certain user
api.view('someuser')

# Showing the visitors of your profile
users = api.visitors()
print(users)

# Searching for users
options = {
    'age1': '20',
    'age2': '40',
    'sex': ['male', 'female'],
    'continents': ['AF', 'AS', 'EU', 'NA', 'OC', 'SA'],
    'countries': ['US', 'CA', 'UK', 'RU'],
    'keywords': 'travelling',
    'online': True,
    'cityName': 'London'  # Or you can use 'city' with its direct code on the website (it's faster)
}
for user in api.search(options, limit=100, timeout=1.0):
    print(user)

To work with friends and pictures, it is necessary to use uid in methods:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')
api = Api(session)

uid = api.get_uid('someuser')

# Listing friends of the user 'someuser'
friends = api.friends(uid)
print(friends)

# Adding 'someuser' to friends
api.friend_add(uid)

# Removing 'someuser' from friends
api.friend_remove(uid)

# Listing pictures
albums = api.albums(uid)
for album in albums:
    aid = album['aid']
    pictures = api.pictures(uid, aid)
    for picture in pictures:
        print(picture['src'])

Working with the chat is done through thread_id:

from interpals_api import Session, Api

session = Session.login('yourusername', 'yourpassword')
api = Api(session)

uid = api.get_uid('someuser')

# Listing your chats
result = api.chat(count=9, offset=0)
print(result['chats'])

# Staring new chat (getting thread_id)
thread_id = api.get_thread_id(uid)

# Show chat messages
messages = api.chat_messages(thread_id)
print(messages)

# Send new message to the thread
api.chat_send(thread_id, "Hey! How are you?")

# Removing chat
api.chat_delete(thread_id)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

interpals-api-2.1.0.tar.gz (11.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page