Showing posts with label Canakit. Show all posts
Showing posts with label Canakit. 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

Saturday, January 3, 2015

Adventures in Raspberry Pi, First Impressions

                                          My Piary

           Having had a week or so to play with the Raspberry Pi b+.  The possibilities of this device are amazing.  It brings visions of cartridge systems, only your swapping out complete Os's.  So far I've had a chance to play with 3 of the more widely used, RaspbianRetropie, and Kodi, more commonly known as Xbmc. Right off the bat a major difference is felt, yes this is a hobbyist flavor of Pc experience.  Having oft bemoaned not being in full control of "my" devices this was a welcome change, even if it meant some setup required.  For the techie types it's a blast, the versatile nature of the platform allow for usage from, basic computer to robots, or home automation.  For non techies while you may not want to be involved in the setup, you might be surprised by just what this little board could be setup to do for you.  

http://www.canakit.com/raspberry-pi-starter-ultimate-kit.html

        The basics

         Keep in mind the Pi, out of the box is a small main board, so it's all about what you add to it. The peripherals, and software make or break the experience here.  With that in mind, have a case, or some way to mount the board, it would be a shame to short something out before even getting started.  While buying a pre installed/configured  sd card does allow for plug and play type setup. Having a linux or windows based pc is a must if you intend to be more creative on build side.  While there are 4 full sized usb ports on the board, devices like external hd's will need external power source, so a powered usb hub can be almost a mandatory add on.  Have your input devices picked out in advance, if you plan on using your pi for retro gaming, or for streaming video, be sure the devices are supported, and you know where/how to install the drivers.  Command line is your friend.  We are all pretty spoiled by our intuitive gui's, and improvements in voice control.  Getting the most out of the Pi is likely to lead to spending some time in a text only environment. Get a class 10 sd card.  Having used 3 different cards thus far, a google search will yield some good information. A general rule of thumb go for the higher speed.  A wifi usb dongle, with wireless connectivity built into to almost everything these days, this might see obvious.  A really good source for information, ideas, and products is Adafruit Industries.  

        Raspbian

        The linux distro made for the Pi.  These boards we created with education in mind, so packaged in are all sorts of learning tools.  This was my first stop, and is the suggested OS to get a feel for what the Pi is about.  That being said, of the three, this is the one I have spent the least time in.  Going
forward that is sure to change, as it is likely to be the foundation for my next 3 pi projects. Those familiar with linux will be right at home, apple, and windows users will experience a bit of a learning curve.  While apple, and microsoft have been moving toward the OS taking charge of much of the day to day maintenance, linux only does what it's told.  With so many built in, and available development tools. This is a solid foundation to build on. For the application specific diy folks, the OS is built on a core, known to be solid, and designed to run with little to no supervision once set up.
Linux servers have been known to run for years without a reboot.  Certainly will have more to cover on this one in the coming weeks, as it will be the likely OS of my next few projects.


       Retropie

        Ever wanted your own arcade machine, or just hanker for some nostalgic video gaming fun.
 Retropie just might be the answer for you.  From ti99 through to mame, and up till n64 and ps1.  This is an emulation package OS using emulation station.  Configuration can be a bit tricky, and some of the emulators need a bit of tweaking.  When combined with the Pi i/o pinout you can fairly easily create professional level arcade style machines in your home.  For my purpose nothing so elaborate is needed, though I have to admit to a wish to make a dedicated arcade cabinet. Complete with arcade style controls.  Access to literally thousands of games, with the flick of a gamepad almost crosses into choice paralysis.  Setting this one up can be a bit tricky, like so much open source it's not a finished product, but forever a work in progress.  A few of the emulators will take some more time on my part to work out the settings needed.  Some are simple, and worked almost like plug and play. Making your own portable device is a realistic project, or perhaps it's a diy for the car dvd player. Of the three, this one held the most initial excitement for me.  Gaming being near, and dear.  There are just some games that never get remade, or get so changed in the updating, playing them old school is the only solution.  Of the emulators I tried, neogeo, and n64 were not plug and play style ready, and I have yet to spend any time in getting them functional.  N64 locked up the system each time I tried to load a rom, and neogeo didn't seem to function at all. A quick google search leads me to feel these can be fixed for the most part through some configuration.  Once those are functional, and some testing of the ps1 emulator, could see it replace the android mini pc as my goto for retro gaming.


       Kodi

         Kodi, or as formerly known Xbmc is an OS for a media center.  This one was of the three the one that attracted me the least originally.  Having for the last couple of years been using an android mini-pc for almost all my media needs.  I even installed an earlier version of Xbmc on my mini pc at one point.  It did not functional very well, more from the model of mini pc I have than anything else. This less than stellar earlier experience meant I had not really low expectations, just they were virtually non-existent.  Installing it started out just to see what it could do, just how many tricks could this pony learn kind of idea.  To say I have been blown away, is not praise enough, to admit that
losing the use of the Pi has stalled other exploration would be more accurate.   This is an OS designed to be controlled through a remote. Once setup is complete it can often be run right off your existing tv remote, through the hdmi cable.  Many of us are used to having apps on our TV's, netflix, and the like are common fodder for almost ever smart tv around.  Some will probably have like myself been using android mini pc's.  Kodi is like smart tv on steroids, with the ability to integrate your tv service, with data, and streaming services of the web, be prepared to get lost for a few days just playing with all the features.  This can be as custom or generic an experience as desired.  Want to set up a complete home theater experience with one click controls to home automation scripts? You can do that.  How about a central media server with plenty of storage for all your movies, pictures, and music, and access from screen in the house? You can do that!  Being an open source project, find something Kodi doesn't do, and you can learn, and code it, Or at least suggest it to one of the folks in the active community of developers.  When combined with the low power consumption, 24/7 run design of the Pi, Kodi is without a doubt a blast to design your media experience the way you want it.  Forget the ilife, Kodi allows you to really make it your own,


Next will be a vpn pi, just as soon as I can make myself go without kodi for a few days.

Jack
aka
PanseyBard