Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import csv
- import pandas as pd
- import numpy
- import threading
- from IPython.display import display as ds
- filename='C:/code/IntelligentSuit/tweet.csv'
- intel_blue=[0,0,255]
- black=[0,0,0]
- white=[255,255,255]
- red=[255,0,0]
- imec_image=[2,2,2,0,0,0,0,0,0,0,0,0,0,2,2,0,
- 0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2,
- 0,2,0,0,0,0,0,0,0,0,0,0,0,0,2,0,
- 2,2,2,1,0,0,0,1,0,0,0,0,0,2,2,2,
- 0,0,0,1,1,0,1,1,0,0,0,0,0,1,1,1,
- 0,0,0,1,0,1,0,1,0,0,0,0,0,1,0,1,
- 0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,1,
- 0,0,0,0,0,0,0,2,2,2,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,0,
- 0,0,0,0,0,0,0,2,2,0,0,0,0,0,2,0,
- 0,0,0,0,0,0,0,2,0,0,0,0,0,0,2,0,
- 0,0,0,0,0,0,0,2,2,2,0,0,0,1,1,1,
- 0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,
- 0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,
- 0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,
- 0,0,0,0,0,0,0,0,0,1,1,1,0,1,1,1]
- spy_down=[0,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,
- 0,0,2,0,0,2,2,2,2,2,0,0,2,0,0,0,
- 0,0,2,0,2,1,1,1,1,1,2,0,2,0,0,0,
- 0,0,2,0,2,1,2,1,2,1,2,0,2,0,0,0,
- 0,0,2,0,2,1,1,1,1,1,2,0,2,0,0,0,
- 0,0,2,0,2,1,1,1,1,1,2,0,2,0,0,0,
- 0,0,2,0,0,2,2,2,2,2,0,0,2,0,0,0,
- 0,0,0,2,0,0,2,2,2,0,0,2,0,0,0,0,
- 0,0,0,0,2,2,2,2,2,2,2,0,0,0,0,0,
- 0,0,0,0,0,0,2,2,2,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,2,0,2,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
- spy_image=[0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,
- 0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,
- 0,0,0,1,1,2,2,2,2,2,2,2,1,1,0,0,
- 0,0,0,1,1,2,2,2,2,2,2,2,1,1,0,0,
- 0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,
- 0,0,0,1,1,2,1,1,2,1,1,2,1,1,0,0,
- 0,0,0,1,1,2,1,1,2,1,1,2,1,1,0,0,
- 0,0,0,1,1,2,2,2,2,2,2,2,1,1,0,0,
- 0,0,0,0,1,1,2,2,2,2,2,1,1,0,0,0,
- 0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,
- 0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,
- 0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,
- 0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0]
- def Image_Setup():
- """device = Adafruit_NeoPixel(256)
- device.setBrightness(0.01)"""
- intel_blue=[0,0,255]
- black=[0,0,0]
- white=[255,255,255]
- red=[255,0,0]
- image = []
- for idx in range(len(spy_image)):
- if spy_image[idx] == 0:
- image.append(white)
- if spy_image[idx]== 1:
- image.append(intel_blue)
- if spy_image[idx]== 2:
- image.append(black)
- return image
- def Translate_Image(image_in):
- image_out=[]
- for idx in range(len(image_in)):
- if image_in[idx] == 0:
- image_out.append(white)
- if image_in[idx]== 1:
- image_out.append(intel_blue)
- if image_in[idx]== 2:
- image_out.append(black)
- return image_out
- def Free_Image_Setup():
- """device = Adafruit_NeoPixel(256)
- device.setBrightness(0.01)"""
- intel_blue=[0,0,255]
- black=[0,0,0]
- white=[255,255,255]
- red=[255,0,0]
- free_image = Translate_Image(imec_image)
- return free_image
- def blit(image, img_width, location, frame_size):
- frame=[black] * frame_size ** 2
- vert_offset=0
- img_lines = [image[x:x+img_width] for x in range(0,len(image),img_width)]
- for line in img_lines:
- for idx, value in enumerate(line):
- coord = idx+vert_offset+(location[0] % frame_size)+((location[1] % frame_size)*frame_size)
- # HANDLE EDGE SCROLLING
- # print coord, idx, vert_offset, (vert_offset+(location[1]*frame_size)+frame_size)-1, location, frame_size
- if (coord > (vert_offset+(location[1]*frame_size)+frame_size)-1):
- coord = coord - frame_size
- coord = coord % (frame_size ** 2)
- frame[coord] = value
- vert_offset += frame_size
- return frame
- def display(width, frame):
- lines = [frame[x:x+width] for x in range(0,len(frame),width)]
- flipped_frame =[]
- for idx,line in enumerate(lines):
- if idx % 2 == 0:
- flipped_frame+=reversed(line)
- else:
- flipped_frame+=line
- # for idx, color in enumerate(flipped_frame):
- # device.setPixelColorRGB(idx, color[0], color[1], color[2])
- # device.show()
- def Vertical_Scroll(image):
- x=0
- y=0
- vert=1
- horiz=0
- while y < 16:
- frame = blit(image, 16, [x,int(y)], 16)
- print y
- #display(16, frame)
- time.sleep(0.2)
- y+=1
- def Horizontal_Scroll(image):
- x=0
- y=0
- vert=0
- horiz=1
- while x < 16:
- frame = blit(image, 16, [x,int(y)], 16)
- print x
- #display(16, frame)
- time.sleep(0.2)
- x+=1
- def printdiffs(df_in):
- df_in = find_diffs(df_in)
- return df_in
- def find_diffs(df_in):
- df_latest = pd.read_csv(filename)
- # print("old frame is:\n{}".format(df_in))
- # print("newdata frame is:\n{}".format(df_latest))
- diff_df = pd.merge(df_latest, df_in, how='outer', indicator='Exist')
- print 'old dataframe size is' + str(df_in.size)
- print 'new dataframe size is' + str(df_latest.size)
- diff_df = diff_df.loc[diff_df['Exist'] != 'both']
- print 'new dataframe size is' + str(diff_df.size)
- if diff_df.size >= 1:
- print 'diff found ' + str(diff_df.size)
- print str(diff_df.size)
- ds_list = df_latest.values[-1].tolist()
- print ds_list[1]
- print "just the value" + str(df_latest[1])
- df_in = df_latest
- return diff_df
- if __name__== '__main__':
- df_last = pd.DataFrame()
- df_in = pd.DataFrame()
- df_in = pd.read_csv(filename)
- #csvFile.close()
- i=0
- while True:
- print("Polling Tweets")
- imageToDisplay=Free_Image_Setup()
- print(imageToDisplay)
- print "free image"
- Horizontal_Scroll(imageToDisplay)
- df_last= printdiffs(df_in)
- print "# new tweets" + str(df_last.size)
- time.sleep(7)
- i = i +1
- if (df_last.size > 0):
- imageToDisplay=Image_Setup()
- print(imageToDisplay)
- print "spy"
- Horizontal_Scroll(imageToDisplay)
- df_last = df_in
- # else:
- # imageToDisplay=Free_Image_Setup()
- # print "free"
- # print(imageToDisplay + "Free Image" )
- # #Horizontal_Scroll(imageToDisplay)
- """
- def Vertical_Scroll(image):
- x=0
- y=0
- vert=1
- horiz=0
- while y < 16:
- frame = blit(image, 16, [x,int(y)], 16)
- print frame
- display(16, frame)
- time.sleep(0.2)
- y+=1
- def Horizontal_Scroll(image):
- x=0
- y=0
- vert=0
- horiz=1
- while x < 16:
- frame = blit(image, 16, [x,int(y)], 16)
- print frame
- display(16, frame)
- time.sleep(0.2)
- x+=1
- if __name__ == "__main__":
- device = Adafruit_NeoPixel(256)
- device.setBrightness(0.01)
- df_last = pd.DataFrame()
- df_in = pd.DataFrame()
- df_in = pd.read_csv(filename)
- i=0
- while True:
- print("Polling Tweets")
- imageToDisplay=Free_Image_Setup()
- print(imageToDisplay)
- Horizontal_Scroll(imageToDisplay)
- df_in= printdiffs(df_in)
- time.sleep(7)
- i = i +1
- if (df_in.size >> 1):
- imageToDisplay=Image_Setup()
- print(imageToDisplay)
- Horizontal_Scroll(imageToDisplay)
- else:
- imageToDisplay=Free_Image_Setup()
- print(imageToDisplay)
- Horizontal_Scroll(imageToDisplay)
- """
- # i=0
- # j=0
- # last_tweet=""
- # tweet_date=""
- # tweet_text=""
- # with open(filename, 'r') as f:
- # for row in reversed(list(csv.reader(f))):
- # if i==0:
- # print(', '.join(row))
- # i+=1
- # if row == last_tweet:
- # break
- # else:
- # for column in row:
- # if j==0:
- # if tweet_date=="":
- # tweet_date=column
- # print tweet_date
- # if j==1:
- # tweet_text=column
- # print tweet_text
- # j=+1
- # if last_tweet == "":
- # last_tweet = row
- # print last_tweet
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement