Showing posts with label bot. Show all posts
Showing posts with label bot. Show all posts

Monday, April 6, 2015

Python Twitter Bot with Tweepy

In an earlier post I laid out a bit how I was working on a twitter bot to automate the promotion of this blog.  I'm a slacker, that has a bad rap for many folks, for me it's the highest calling I can aspire. Get the most accomplished, with the least effort, and disturbance. In the words of Bruce Lee, "Be Like Water, My Friend".  In the dao of piglet, and the te of poo, it's the mystery of being the uncarved block. In the teachings of the Kabbalah or Quabbalah, which was made into such nice easy pictograms in traditional tarot, it's learning to be representative of any, while maintaining your own sense of self.  I have one Boss, and I'm really hoping that Boss never shows up, but I always am sure to recognize There is always a bigger fish. When I crashed the party of social media a few years back, it was never intended to a social outlet. I had already experienced that in years of mmorpg's, irc, bbs, going back to wargames dialers, and phone phreaking. What I was always best at was social hacking, a rather disturbing art when taken to the level of social engineering, or mass media marketing.  After all the drugs, meditation, and study I did over the course of  a lifetime, I finally started to see a pattern, it's not even an unknown pattern, matter of fact it's all over the place, or at least portions of it are.  When I finally awoke to what I had been attempting to understand, about people, and their place in creation, I found that I had missed the relative short window of opportunity to be counted among those who's say carried any weight. In social media I saw an opportunity to leverage the flood of information as a means to get ideas running through my mind. into the hands of those who could make use of them.  I accidently crashed the party of the twitter follow gangs, that handle the bulk of the twitter advertising. It's a fairly ingenious method of leveraging the split platforms of twitter, and sms, in concert to trade influence in the twitter verse. I just saw it as an expedient means of sharing ideas to everyone as quickly as possible, regardless of how they were accepted. I even refused ever offer of easy income, not out a disdain for the finer things the world has to offer, but from an understanding of the myth of an infinite growth paradigm in a zero sum game. I'm speaking of the effects of compounding interest on privatized currency creation. The same effect is seen again and again in almost every market. It's the money itself I have issue with, not currency as an idea. The accounting for who has what, and why, is important. In our current system so many are being left behind, not out of ability, but just by becoming a party to the madness which has a seeming strangle hold on our global civilization. The worship of money, and idol, a representation of something only in potential.  As I said I'm an old school hacker, I once streamlined a system for reporting the percentage of the utilities used in manufacturing in New York state were taxable.  Was a great job while it lasted, at 18 having a work from home job for 10 or 12 an hour is amazing. Taking the time each reports takes to generate from 6 hours to 2 hours, and being told your services are no longer required, not so amazing. Being allowed to help a crop of Police Officers pass a class they had no reason taking, Amazing!. Having your professor tell you there is no place in the world for programming games, again not so amazing. I stopped using computers, and started playing games with them, and then started fixing them.  In the course of my several years of tech service for a local community, what I found was they didn't actually want for me to really solve the issues, they wanted me to manage the problems that cropped up with using outdated, or mixed era systems. Sometimes they almost wanted me to take over the day to day operations of their endeavors. All well and good if it is a mentor situation, when it's a lack of desire to stay current enough to manage your own affairs, well if your not the adult, there aren't many roles left.  After exhausting some of the more entertainment oriented uses for the raspberry pi b+ I turned to what else could this little marvel do. I started seeing vpn's, and pirate drop boxes, wifi extenders to create public clouds all over. All cool concepts, but not much use to me personally, given my current circumstance. Realizing I needed to have a bit of programing brush up, I think the last time I wrote code before this was 88 or so. I hit up code academy, and picked python as it is a seemingly popular high lvl language with many popular api's. I also did some html work, I get it, and it's powerful, it's just puts me to sleep doing it. Even in python as entertaining as it was to create the bot as far as I've taken it, and I am well aware how limited it is in it's current state.  It's basic, but it will tweet for you, pick from search terms to promo others, so your account generates more attention from the community, and will auto follow new folks, and unfollow those that are just attempting to boost numbers. Once I got there essentially I had a automatic twitter promotional bot. Did you know people get paid for doing promotional work on twitter? Even though it makes sense from the marketing game standpoint, that is a slippery area, we are talking about folks that have no moral issue with using psych jobs on children to profit.
So today I'm going post the code for my bot friend. working title was twitternanny, but for easy of use I have taken to naming them after the account they manage. I currently have 2 instances running on my raspberry pi. They may come down at the end of the month, as I have already given notice, my leap of faith I guess, with no place on horizon as of yet. I guess I could always battery power it, and stick in an open wifi cloud in a tree or something, but what would be the point. I ended up using twitter as an object lesson of the insanity of exclusivity.
Enough of my ramble, I get sick of myself sometimes.
here is the code, use it abuse it.



def hourlytweet():
    filename=open(argfile,'r')
    f=filename.readlines()
    filename.close()
    api.update_status(status=f)
    print("hourly tweet posted")


def follow_unfollow():
    followers = api.followers_ids()
    friends = api.friends_ids()

    for z in followers:
        if z not in friends:
            api.create_friendship(z)

    for z in friends:
        if z not in followers:
            api.destroy_friendship(z)
    print("follow, unfollow done")


def search_retweet():
        search_terms= ['python', 'technology', 'raspberry pi', 'ingress', 'news', 'breaking']
        g = random.choice(search_terms)
        g = '#' + g
        results = api.search(q=g, count=1)
        for u in results:
            if u not in alreadytweeted:
                api.retweet(u.id)
                print("retweeted top result for", g)
                alreadytweeted.append(u)



x=1
y=2

while x<y:
    localtime = time.asctime(time.localtime(time.time()))
    hour = int(localtime[11] + localtime[12])
    print('current hour is:',hour)
    if hour>5 and hour<24:
        try:
            hourlytweet()
            time.sleep(1700+random.randint(200,400))
        except:
            print("could not post hourly tweet")
            time.sleep(1700+random.randint(200,400))
        try:
            search_retweet()
            follow_unfollow()
        except:
            print("could not post retweet")
    elif hour == 24 or hour < 6:
        try:
            search_retweet()
            follow_unfollow()
        except:
            pass
    time.sleep(1700+random.randint(200,400))

some of the basic framework came form http://www.dototot.com/how-to-write-a-twitter-bot-with-python-and-tweepy/
So big ups and respect, thanks for the head start, and to those I didn't mention, sorry I use many reference sources when I start a little project.

Thanks
Jack
aka
PanseyBard Digital PiedPiper

Wednesday, March 25, 2015

Trying a Different Approach

I am a slacker, my life is a cautionary tale, not something to aspire to or emulate.  Do not misconstrue that the I in me would wish to be any other than me.  Only that the emotional, and psychological traumas I needed to inflict upon myself to become as I am, are not anything I would wish upon anyone.  In searching answers to those ultimate questions I pulled an icarus. Not once, or even twice, nah I'm not that bright.  I had to push it till it cost me my top teeth, and partially my bottom ones, still getting over that one.  People have talked about genetic, cellular and other types of memory.  Now we are even to the point of beginning to grapple with ideas of moving without moving.  It's possible, without a doubt, it's not even that difficult when you've grasped for inkling of our true position in creation, and it fried you back into your place.  We can make black holes, we can warp space and time, we end up in the formless abyss, and no one but our dead mourns our passing.  I love people, I love the planet, all life can snuff out in our little corner of existence, and there might be some metaphorical tears shed on what ever plane of existence you and yours hail from.
Do we really have the right to take chances with the planet, solar system, galaxy, or on and on?
some folks seem to be interested in how I see things, some are offended, I'm ok with that too.  I know what I like, I feel what I need, I feel what the people around me need, using people loosely.
If we meet and you think you would like to chat, I'm happy to do so, if I offend, just tell me to please stop, and go away, and I will.  What I can not abide is total trickery, and dishonesty, I'm to good at it, and it hurts me to much to inflict those kinds injuries on myself.
I'll try to do a better job with some pix, and the like at showing kind of how I see this world, and why sometimes it makes me cry when others are so happy!  btw, if there is any confusion, I an hetrosexual male, that is so in love with women that they are my kryptonite.  it's pretty much the same with everyone, but we all get to pick where, and what we eat right?
Never been suicidal, not that I feel people do not have to right to decide the fate of what can be in this experience the only thing they can ever hope to claim ownership over, which is really just stewardship, we have horribly misunderstood, like so much of our K based systems, in such a rush to get somewhere.  They forgot that Wisdom, knows when, and where to apply knowledge, and thats why Wikipedia, has a capital W. No it's just that what is point of suicide in a zero sum universe. what comes in goes out, it's hotel california, we either come to grips, or we just keep blowing bubbles.

Much Love
Jack

there was a song from when I was teenage drunken drop out in the punker days

If some of your brightest kids are seemingly like the metaphors in this song, you might wanna take a look in the mirror before asking how things got this bad.  I was almost a perfect reflection of a child raised for the most part by the stuff around me, mostly tv, music, games, starting as early as I can remember.  I was never mommies monster at all, just a reflection of the monsters so many of us have become.
gonna try to finish up some e-mails, change get outside, and upload some pictures to instagram, in case anyone is curious what I'm about today.

Thursday, February 19, 2015

Python, Tweepy, and Twitter.....Oh My!!!!

      If you landed here from twitter chances are you clicked a link provided by a bot.  This is not uncommon, everyday the access to easy to use development tools becomes more widespread.  Having not written a line of code since the late 80's imagine my surprise at how quickly a site like  codecademy walk me through entry level python.  Six days after the whim to check out python found me looking for a entry level project to solidify my newly acquired knowledge, and expose how sorely it was lacking.  So why a twitter bot?  I do not take things overly seriously.  That being said, I respect that other people do.  In twitter there is from my perspective a unique venue of real world interaction on a scale normally reserved for a few, along with low impact.  Meaning I am unlikely to cause anyone harm while messing around and learning, So while this is not intended in anyway to be a tutorial. After 6 days of an online course, and 3 days of playing, I hardly qualify.  The bot code currently looks like this:

#imports modulesimport tweepy, time, sys, random

#assigns text file arguments to variablesargfile = str(sys.argv[1])

#enter the corresponding information from your Twitter application:
CONSUMER_KEY = '123456'#keep the quotes, replace this with your consumer keyCONSUMER_SECRET = '123456'#keep the quotes, replace this with your consumer secret keyACCESS_KEY = '123456'#keep the quotes, replace this with your access tokenACCESS_SECRET = '123456'#keep the quotes, replace this with your access token secretauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

#sets up tweepy apiapi = tweepy.API(auth)


def hourlytweet():
    filename=open(argfile,'r')
    f=filename.readlines()
    filename.close()
    api.update_status(status=f)
    print("hourly tweet posted")


def follow_unfollow():
    followers = api.followers_ids()
    friends = api.friends_ids()

    for z in followers:
        if z not in friends:
            api.create_friendship(z)

    for z in friends:
        if z not in followers:
            api.destroy_friendship(z)
    print("follow, unfollow done")

def search_retweet():
        search_terms= ['python','technology','raspberry pi','anonymous','twitter bots']
        g = random.choice(search_terms)
        results = api.search(q=g, count=1)
        for u in results:
            api.retweet(u.id)
            print("retweeted top result for", g)



x=1y=2
while x<y:
    localtime = time.asctime(time.localtime(time.time()))
    hour = int(localtime[11] + localtime[12])
    print('current hour is:',hour)
    if hour>5 and hour<24:
        hourlytweet()
        time.sleep(1700+random.randint(200,400))
        search_retweet()
    elif hour == 24:
        follow_unfollow()
    time.sleep(1700+random.randint(200,400))


It currently has the basic functions, between 6am, and midnight local time, it will tweet from a textfile, than wait roughly 30 min. Perform a search on a term selected randomly from a list, and retweet the top result. wait roughly 30min and start over. At midnight, it will check for new followers and follow them, then check for unfollowers, and unfollow them.  Next I'll be looking at adding some more functionality, perhaps checking for mentions, and favorites.  Maybe adding in an exit condition, other than a crash or keyboard break.

Thanks for reading
and always make up your own damn mind

Jack
aka
PanseyBard

Tuesday, February 17, 2015

Pseudo Productivity, or....Filling the Void.

The Setup:

     I grew up an only child, raised by a single mother who worked, and finished her education during most of my childhood.  This means I learned quite early how to be with myself as my only company. A nice match for my natural introvert tendencies. For reasons beyond the scoop of today's posting this proclivity for the avoidance of social interaction has gone from mildly reclusive, to almost full blown hermit over the course of the last year plus.  With freeing of time has come the desire to fill it with something other than movies, games, and maryjane.  So like many I have turned to learning, and as a tech lover, many of learning choices have been in that direction.


The Flourish:

      Once the wallowing in self pity ebbed to a point where the desire for activity could rise through the fog of self medication. What has become a concept of pseudo-productivity began.  An interesting concept in itself, basically meaning structured, goal oriented activity, where the activity is the reward. Video games are great examples of pseudo-productivity, having purpose only within the context of the game, and no real bearing outside itself.  The sense of accomplishment achieved can have profound effects on the psyche both positive, as well as negative.  Leading to a greater healing, or descending into a false sense stability.  So between scrambling to keep enough currency flowing to maintain my meager lifestyle, while avoiding as much face to face social interaction with public. I've had plenty of pseudo productivity, some days even measuring my day in these terms only.  


The Reveal:

     When the student is ready the teacher shall appear, seemingly extends far into abstraction.  Back in December a friend gifted me with a Raspberry Pi b+, and it quickly became a great outlet for my desire for productivity.  Though after running through Kodi(raspbmc),  Retropie, and the basics of Raspbian.  It became abundantly clear how end user oriented my interaction with technology had become.  While this serves me quite nicely in helping other end users, it does little to really give a sense of creative outlet.  It's more about being about to understand and follow directions, with being creative being a hinderance.  Than came some practical use ideas of said Pi, a vpn, personal cloud storage, a local file sharing node(priate box), to name a few.  Of course these all have the same fatal flaw, it's just following directions to setup.  In learning about the Pi, the linux environment, and development.  I became exposed to modern programming languages, having stayed away from the software side since the late 80's.  Exactly as the Pi's creators intended, my inner child responded. With the Pi as my platform, the language of choice was made easy, python. Off to Codecadey for an interactive course. Big ups to the folks over there, the interface is great, being able to code right in the browser, and receive instant feedback makes for an enjoyable experience.  Only issue with that was an odd interaction with the chrome instant translate extension wanting to translate my code as I wrote it.  Six days later, now I need to use it, or like so many things it will be quickly forgotten, but what to make.  If you came upon this blog from twitter, than you likely have already encountered my starter project.  A Pi based Twitter bot, big thanks to Dototot for the basic idea, and a framework to start from.  Thus far it's very limited, only tweeting once roughly an hour. A future post will go more in depth on the bot itself, but given it's rudimentary nature. That would be premature.


Share, Flame, Whatever
Just make up your own damn mind

Jack
aka
PanseyBard