Skip to content

Instantly share code, notes, and snippets.

@jfrobbins
Last active December 19, 2015 16:39
Show Gist options
  • Select an option

  • Save jfrobbins/5985628 to your computer and use it in GitHub Desktop.

Select an option

Save jfrobbins/5985628 to your computer and use it in GitHub Desktop.
follow a list of line delimited users (ie. dianara followers export)
#! /usr/bin/env python3
import sys
import os
import subprocess
from time import sleep
'''
This is a hack that lets you sub to a bunch of users that are line-delimited in a file.
The Dianara client currently can export such a list.
This script requires that you:
1) have Node installed ( http://nodejs.org/ )
2) have cloned the pump repo, or at least have the bin files (https://github.com/e14n/pump.io)
It is not a clean solution, but it is a quick working solution to do this.
Once all of the auth stuff can be done in python I can clean this up quite a bit.
###
example:
edit the params below, or leave them blank
$python3 pump_sub_list.py --setup -f dianara_export.txt
###
'''
binDir = '../bin' #update this to your pump.io bin dir, or blank if you have it in your $PATH?
user = 'jrobb'
server = 'microca.st'
port = '443'
pumpFollow = os.path.join(binDir, 'pump-follow') #follow by default
def authorizeApp():
pumpRegisterApp = os.path.join(binDir, 'pump-register-app')
pumpAuthorize = os.path.join(binDir, 'pump-authorize')
toolName = 'CLI'
print('authorizing the cli tools')
subprocess.call(['node', pumpRegisterApp, '-s', server, '-P', port, '-t', toolName])
subprocess.call(['node', pumpAuthorize, '-s', server, '-P', port, '-u', user])
def checkForInfo():
global user
global server
global port
if user == '' or user == None:
user = input("enter username [ie. jrobb]:")
if not user:
user = 'jrobb'
if server == '' or server == None:
server = input("Enter server [microca.st]:")
if not server:
server = 'microca.st'
if port == '' or port == None:
port = input("Enter port [443]:")
if not port:
port = '443'
def main(args):
doAuthorize = False #use '--setup' flag to make True
inFile = None
follow = True
other = None
if len(args) <= 0:
print('no file/args specified')
sys.exit()
if len(args) == 1 and ('--' not in args[0][:2]):
inFile = args[0]
else:
for n in range(0, len(args)):
if args[n] == '-f':
#file for input
inFile = args[n+1]
elif args[n] == '--setup':
#re-do authentication
doAuthorize = True
elif args[n] == '--unfollow' or args[n] == '-u':
#unfollow
follow = False
elif args[n] == '--other' or args[n] == '-o':
#other user/etc
n += 1
other = args[n]
checkForInfo()
if doAuthorize:
authorizeApp()
if inFile == None and other == None:
print('done (no file specified-- auth only?)')
sys.exit()
if other == None:
if not os.path.isfile(inFile):
print(inFile + ' is not a valid file.')
sys.exit()
with open(inFile, 'r') as f:
print("file is opened")
sfile = f.readlines() #read the lines into a list
f.close()
else:
sfile = [other]
if sfile:
if follow == False:
#unfollow instead
pumpFollow = os.path.join(binDir, 'pump-stop-following')
for userToFollow in sfile:
if follow:
print('trying to sub: ' + userToFollow)
else:
print('trying to UNsub: ' + userToFollow)
subprocess.call(['node', pumpFollow, '-s', server, '-u', user, '-P', port, '-o', userToFollow])
sleep(0.1)
print('done subbing')
else:
print('file could not be read')
sys.exit()
if __name__ == '__main__':
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment