Skip to content

Commit

Permalink
Updated samples and credentials provider
Browse files Browse the repository at this point in the history
  • Loading branch information
hadiyarajesh committed Feb 24, 2021
1 parent 8ae4b7e commit bf30e11
Show file tree
Hide file tree
Showing 29 changed files with 231 additions and 211 deletions.
52 changes: 0 additions & 52 deletions build.gradle

This file was deleted.

54 changes: 54 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
kotlin("jvm") version "1.4.30"
id("org.jetbrains.dokka") version "1.4.20"
}

group = "com.hadiyarajesh"
version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
jcenter()
maven(url = "https://jitpack.io")
}

sourceSets {
main {
java.srcDir("src/main/kotlin")
}
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3")
implementation("com.github.jkcclemens:khttp:-SNAPSHOT")
implementation("com.nfeld.jsonpathlite:json-path-lite:1.1.0")
implementation("org.json:json:20180813")
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dokkaSourceSets {
named("main") {
moduleName.set("instagram-api")
includeNonPublic.set(false)

perPackageOption {
matchingRegex.set("api($|\\.).*") // will match all api packages and sub-packages
suppress.set(true)
}
perPackageOption {
matchingRegex.set("util($|\\.).*") // will match all util packages and sub-packages
suppress.set(true)
}
perPackageOption {
matchingRegex.set("samples($|\\.).*") // will match all samples packages and sub-packages
suppress.set(true)
}
perPackageOption {
matchingRegex.set("com.nfeld.jsonpathlite($|\\.).*") // will match all com.nfeld.jsonpathlite packages and sub-packages
suppress.set(true)
}
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Tue Dec 24 00:37:30 CST 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle

This file was deleted.

9 changes: 9 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rootProject.name = "InstagramAPI"

pluginManagement {
repositories {
gradlePluginPortal()
jcenter()
}
}

54 changes: 28 additions & 26 deletions src/main/kotlin/BotTest.kt
Original file line number Diff line number Diff line change
@@ -1,45 +1,47 @@
import bot.InstagramBot
import kotlinx.coroutines.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking

@InternalCoroutinesApi
@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
bot.login(username, password)

/**
* Minimum and maximum time to sleep before performing next action.
* Minimum and maximum time (in seconds) to wait before performing next action.
* Actual time will be randomly generated each time between min and max time
*/

bot.minSleepTime = 100
bot.maxSleepTime = 200
bot.minSleepTime = 150
bot.maxSleepTime = 300

// Provide your comment list here
val commentsList = listOf("Sample comment 1", "Sample comment 2")
val userList = listOf("username1", "username2")
// Provide your username list here
val userList = listOf("user_name_1", "user_name_2")

runBlocking {
// Get your own followers
bot.getSelfFollowing(Int.MAX_VALUE).collect { println(it) }
// Get 100 followers of given username
bot.getUserFollowers("user_name", 100, isUsername = true).collect { println(it) }
// Like 5 medias from explore page
bot.likeMediasByExplorePage(5).collect { println(it) }
// Comment 5 medias having given hashtag and given comment list
bot.commentMediasByHashTag("hashtag_name", commentsList, 5).collect { println(it) }
// Follow given list of users
bot.followUsers(userList).collect { println(it) }
// Approve all pending follow requests
bot.approveAllPendingFollowRequests().collect { println(it) }
// Watch stories of 200 users based on given location
bot.watchLocationUsersStories("location_name", 200).collect { println(it) }
// Download latest 5 medias of given username along with caption
bot.downloadUserMedias("user_name", 5, true).collect { println(it) }
}
// Get your own followers
bot.getSelfFollowing(Int.MAX_VALUE).collect { println(it) }
// Get 100 followers of given username
bot.getUserFollowers("enter_user_name_here", 100, isUsername = true).collect { println(it) }
// Like 5 medias from explore page
bot.likeMediasByExplorePage(5).collect { println(it) }
// Comment 5 medias having given hashtag and given comment list
bot.commentMediasByHashTag("enter_hashtag_name_here", commentsList, 5).collect { println(it) }
// Follow given list of users
bot.followUsers(userList).collect { println(it) }
// Approve all pending follow requests
bot.approveAllPendingFollowRequests().collect { println(it) }
// Watch stories of 200 users based on given location
bot.watchLocationUsersStories("enter_location_name_here", 200).collect { println(it) }
// Download latest 5 medias of given user along with caption
bot.downloadUserMedias("enter_user_name_here", 5, true).collect { println(it) }
}
4 changes: 4 additions & 0 deletions src/main/kotlin/Credentials.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Credentials {
const val USERNAME = "enter_your_instagram_username_here"
const val PASSWORD = "enter_your_instagram_password_here"
}
2 changes: 2 additions & 0 deletions src/main/kotlin/api/InstagramAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import java.util.*
import kotlin.math.max
import kotlin.math.min
import kotlin.random.Random
import kotlin.system.exitProcess

object InstagramAPI {
var username: String = "username"
Expand Down Expand Up @@ -144,6 +145,7 @@ object InstagramAPI {
return true
} else {
println("Username or password is incorrect.")
exitProcess(1)
}
}
return false
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/samples/comment/CommentExploreTabMedias.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package samples.comment

import Credentials
import bot.InstagramBot
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
Expand All @@ -18,7 +19,5 @@ fun main() {
val commentList = listOf("Comment 1", "Comment 2")
val howManyMediasYouWantToComment = 10

runBlocking {
bot.commentMediasByExplorePage(commentList, howManyMediasYouWantToComment).collect { println(it) }
}
bot.commentMediasByExplorePage(commentList, howManyMediasYouWantToComment).collect { println(it) }
}
11 changes: 5 additions & 6 deletions src/main/kotlin/samples/comment/CommentHashTagMedias.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package samples.comment

import Credentials
import bot.InstagramBot
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
Expand All @@ -19,7 +20,5 @@ fun main() {
val commentList = listOf("Comment 1", "Comment 2")
val howManyMediasYouWantToComment = 10

runBlocking {
bot.commentMediasByHashTag(hashTagName, commentList, howManyMediasYouWantToComment).collect { println(it) }
}
bot.commentMediasByHashTag(hashTagName, commentList, howManyMediasYouWantToComment).collect { println(it) }
}
11 changes: 5 additions & 6 deletions src/main/kotlin/samples/comment/CommentLocationBasedMedias.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package samples.comment

import Credentials
import bot.InstagramBot
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
Expand All @@ -19,7 +20,5 @@ fun main() {
val commentList = listOf("Comment 1", "Comment 2")
val howManyMediasYouWantToComment = 10

runBlocking {
bot.commentMediasByLocation(locationName, commentList, howManyMediasYouWantToComment).collect { println(it) }
}
bot.commentMediasByLocation(locationName, commentList, howManyMediasYouWantToComment).collect { println(it) }
}
17 changes: 8 additions & 9 deletions src/main/kotlin/samples/dm/SendHashTagToTimeLineUsers.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package samples.dm

import Credentials
import bot.InstagramBot
import com.nfeld.jsonpathlite.extension.read
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
Expand All @@ -21,9 +21,8 @@ fun main() {
val hashTagName = "enter_hashtag_name_here_without_#"
val textName = "enter_text_name_to_send_along_with_hashtag"

runBlocking {
bot.sendDirectHashTagToUsers(bot.getUsersByTimeline().map { it.get("pk").toString() }.toList(),
hashTagName, textName).collect { println(it) }
}

bot.sendDirectHashTagToUsers(
bot.getUsersByTimeline().map { it.get("pk").toString() }.toList(),
hashTagName, textName
).collect { println(it) }
}
12 changes: 5 additions & 7 deletions src/main/kotlin/samples/dm/SendLikeToAllYourFollowers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking

@ExperimentalCoroutinesApi
fun main() {
fun main() = runBlocking {

val username = "your_instagram_username"
val password = "your_instagram_password"
val username = Credentials.USERNAME
val password = Credentials.PASSWORD

val bot = InstagramBot()
bot.prepare(username)
bot.login(username, password)

runBlocking {
val yourFollowers = bot.getSelfFollowers().toList()
bot.sendDirectLikeToUsers(yourFollowers).collect { println(it) }
}
val yourFollowers = bot.getSelfFollowers().toList()
bot.sendDirectLikeToUsers(yourFollowers).collect { println(it) }
}
Loading

0 comments on commit bf30e11

Please sign in to comment.